********************************************************************************
* DECOMPOSING CULTURE                                                          *
* AN ANALYSIS OF GENDER, LANGUAGE, AND LABOR SUPPLY IN THE HOUSEHOLD           *
*                                                                              *
* GAY, HICKS, SANTACREU-VASUT AND SHOHAM (2017)                                *
*                                                                              *
* ACCEPTED AT THE REVIEW OF ECONOMICS OF THE HOUSEHOLD                         *
*                                                                              *
* CODERS: V. GAY AND D. L. HICKS                                               *
*                                                                              *
* CREATION:    11/25/2016                                                      *
* LAST EDITED: 03/17/2017                                                      *
********************************************************************************

*****************
* Program Setup *
*****************

version 13
clear all
set more off

*************
* DIRECTORY *
*************

* INDICATE DIRECTORY PATH HERE

cd ""

***********
* GLOBALS *
***********

* CREATE TWO FOLDERS FOR TABLES AND FIGURES OUTPUT AND INDICATE PATH HERE

global TABLES  ""
global FIGURS  ""

* DOWNLOAD THE DATA AT THE LINKS PROVIDED IN THE README FILE
* SAVE THE DATA IN THE DIRECTORY                            

********************************************************************************
* TABLE OF CONTENTS                                                            *
*                                                                              *
* PART 1: PAPER                                                                *
*   TABLE 1: SUMMARY STATISTICS                                                *
*   TABLE 2: SUMMARY STATISTICS, LANAGUAGE VARIABLES                           *
*   TABLE 3: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL   *
*   TABLE 4: LANGUAGE STRUCTURE AND HOUSEHOLD BARGAINING                       *
*   TABLE 5: LINGUISTIC HETEROGENEITY IN THE HOUSEHOLD                         *
*   TABLE 6: LANGUAGE AND SOCIAL INTERACTIONS                                  *
*   TABLE 7: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION ADDITIONAL OUTCOMES *
*                                                                              *
* PART 2: APPENDIX                                                             *
*   TABLE C1: LANGUAGE DISTRIBUTION BY FAMILY IN THE REGRESSION SAMPLE         *
*   TABLE C2: SUMMARY STATISTICS, NO SAMPLE SELECTION                          *
*   TABLE C3: SUMMARY STATISTICS, HUSBANDS                                     *
*   TABLE C4: SUMMARY STATISTICS, HOUSEHOLDS                                   *
*   TABLE C5: SUMMARY STATISTICS, COUNTRY AND COUNTY-LEVEL VARIABLES           *
*   TABLE C6: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL  *
*   TABLE C7: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, ADL OUTCOMES      *
*   TABLE C8: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, ALT SAMPLES       *
*   TABLE C9: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, LOGIT AND PROBIT  *
*   TABLE C10: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL *
*   TABLE C11: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION                   *
*   TABLE C12: LANGUAGE AND HOUSEHOLD BARGAINING                               *
*   TABLE C13: LINGUISTIC HETEROGENEITY IN THE HOUSEHOLD                       *
*   FIGURE D1: REGRESSION WEIGHTS FOR TABLE 3 COLUMN 5                         *
********************************************************************************

*****************
* PART 1: PAPER *
*****************

timer clear
timer on 1

* TABLE 1: SUMMARY STATISTICS
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** SUMMARY STATISTICS, INDIVIDUAL CHARACTERISTICS

local variables "age yrsusa ageimmig student educyrs educ4"
local variables "`variables' educ2 educ3 educ1 race1 race2 race4 race3 hispan"
local variables "`variables' speakeng1 speakeng4 speakeng3 speakeng2"
local variables "`variables' lfp emp wks wks0 hrs hrs0 incwage inctot"

foreach v of local variables {

	/* summary statistics */

	summarize `v' [aw=perwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* SB1 - SB0 */
	
	regress `v' sbi [pw=perwt], robust
	parmest, saving(`v', replace)
}

** SUMMARY STATISTICS, HOUSEHOLD CHARACTERISTICS

local variables "timemarr nchild_l5 nchild hhsize hhinc"

foreach v of local variables {

	/* summary statistics */

	summarize `v' [aw=hhwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* SB1 - SB0 */
	
	regress `v' sbi [pw=hhwt], robust
	parmest, saving(`v', replace)
}	

** DATASET OF SUMMARY STATISTICS AND ESTIMATES

matrix TABLE1 = J(31,10,.)

local variables "age yrsusa ageimmig student educyrs educ4"
local variables "`variables' educ2 educ3 educ1 race1 race2 race4 race3 hispan"
local variables "`variables' speakeng1 speakeng4 speakeng3 speakeng2"
local variables "`variables' lfp emp wks wks0 hrs hrs0 incwage inctot"
local variables "`variables' timemarr nchild_l5 nchild hhsize hhinc"

local j = 0
foreach v of local variables {
	local j = `j' + 1
	
	use `v', clear
	
	matrix TABLE1[`j',1] = `j'                        /* variable name        */
	matrix TABLE1[`j',3] = mean_`v'                   /* mean                 */
	matrix TABLE1[`j',4] = sd_`v'                     /* s.d.                 */
	matrix TABLE1[`j',5] = min_`v'                    /* min                  */
	matrix TABLE1[`j',6] = max_`v'                    /* max                  */
	matrix TABLE1[`j',7] = n_`v'                      /* observations         */
	matrix TABLE1[`j',8] = estimate[1]                /* estimates on SBI = 1 */
	matrix TABLE1[`j',9] = p[1]                       /* p-value              */
	
	erase `v'.dta
}

drop _all
svmat TABLE1

rename TABLE11  variable
rename TABLE12  level
rename TABLE13  mean
rename TABLE14  sd
rename TABLE15  min
rename TABLE16  max
rename TABLE17  n
rename TABLE18  estimate
rename TABLE19  p
rename TABLE110 stars

foreach v of varlist variable-level stars {
	tostring `v', replace
}

local i = 1
replace variable = "age"        if variable == "`i'"
local i = `i' + 1
replace variable = "yrsusa"     if variable == "`i'"
local i = `i' + 1
replace variable = "ageimmig"   if variable == "`i'"
local i = `i' + 1
replace variable = "student"    if variable == "`i'"
local i = `i' + 1
replace variable = "educyrs"    if variable == "`i'"
local i = `i' + 1
replace variable = "educ4"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ2"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ3"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race2"      if variable == "`i'"
local i = `i' + 1
replace variable = "race4"      if variable == "`i'"
local i = `i' + 1
replace variable = "race3"      if variable == "`i'"
local i = `i' + 1
replace variable = "hispan"     if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng1"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng4"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng3"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng2"  if variable == "`i'"
local i = `i' + 1
replace variable = "lfp"        if variable == "`i'"
local i = `i' + 1
replace variable = "emp"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks0"       if variable == "`i'"
local i = `i' + 1
replace variable = "hrs"        if variable == "`i'"
local i = `i' + 1
replace variable = "hrs0"       if variable == "`i'"
local i = `i' + 1
replace variable = "incwage"    if variable == "`i'"
local i = `i' + 1
replace variable = "inctot"     if variable == "`i'"
local i = `i' + 1
replace variable = "timemarr"   if variable == "`i'"
local i = `i' + 1
replace variable = "nchild_l5"  if variable == "`i'"
local i = `i' + 1
replace variable = "nchild"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhsize"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhinc"      if variable == "`i'"

replace level = "respondent"
replace level = "household" if variable == "hhsize" | variable == "nchild"   ///
							 | variable == "hhinc"  | variable == "timemarr" ///
							 | variable == "nchild_l5"
 
replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1

save "$TABLES\TABLE1", replace

** GENERATE TABLE 1

use "$TABLES\TABLE1", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\table1.tex", text replace
noisily display "\begin{table}[!h]"
noisily display "\centering"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics\\ Female Immigrants, Married, Spouse Present, Aged 25-49}"
noisily display "\begin{tabular}{lccccrr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "                                   & Mean & S.d. & Min. & Max. & Obs. & SB1-SB0 \\"
noisily display " \midrule"
noisily display "                                   & \multicolumn{6}{c}{A. Individual characteristics} \\"
noisily display " \cmidrule(lr){2-7}\\"
local i = 1
noisily display "Age                                &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Years since immigration            &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Age at immigration                 &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Educational Attainment \\"
noisily display "\;\; Current student               &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Years of schooling            &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; No schooling                  &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Elementary                    &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; High school                   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; College                       &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Race and ethnicity \\"
noisily display "\;\; Asian                         &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Black                         &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; White                         &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Other                         &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Hispanic                      &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Ability to speak English \\"
noisily display "\;\; Not at all                    &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Not well                      &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Well                          &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Very well                     &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Labor market outcomes \\"
noisily display "\;\; Labor participant             &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Employed                      &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (excl. 0) &" %9.2fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (incl. 0) &" %9.2fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (excl. 0) &" %9.2fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (incl. 0) &" %9.2fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Labor income (thds.)          &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display " \cmidrule(lr){2-7}"
noisily display "                                   & \multicolumn{6}{c}{B. Household characteristics} \\"
noisily display " \cmidrule(lr){2-7} \\"
local i = `i' + 2
noisily display "Years since married                &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children aged $ < $ 5    &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children                 &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household size                     &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household income (thds.)           &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table1} notes: The summary statistics are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}, except those for household characteristics, which are computed using household weights (\texttt{HHWT}). The last column reports the estimate $\widehat\beta$ from regressions of the type $ X_i=\alpha+\beta\;\texttt{SBI}+\varepsilon $, where $ X_i $ is an individual level characteristic. Robust standard errors are not reported. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table1}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}
* TABLE 2: SUMMARY STATISTICS, LANGUAGE VARIABLES
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** SUMMARY STATISTICS

local variables "sbi ngi gai gpi gai_cond gii_1 gii_2 gii_3 gii_pca"

foreach v of local variables {

	summarize `v' [aw=perwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
}
								
** DATASET OF SUMMARY STATISTICS

matrix TABLE2 = J(9,6,.)

local variables "sbi ngi gai gpi gai_cond gii_1 gii_2 gii_3 gii_pca"

local j = 0
foreach v of local variables {
	local j = `j' + 1
	
	matrix TABLE2[`j',1] = `j'                        /* variable name        */
	matrix TABLE2[`j',2] = mean_`v'                   /* mean                 */
	matrix TABLE2[`j',3] = sd_`v'                     /* s.d.                 */
	matrix TABLE2[`j',4] = min_`v'                    /* min                  */
	matrix TABLE2[`j',5] = max_`v'                    /* max                  */
	matrix TABLE2[`j',6] = n_`v'                      /* observations         */
}

drop _all
svmat TABLE2

rename TABLE21  variable
rename TABLE22  mean
rename TABLE23  sd
rename TABLE24  min
rename TABLE25  max
rename TABLE26  n

tostring variable, replace

local i = 1
replace variable = "sbi"      if variable == "`i'"
local i = `i' + 1
replace variable = "ngi"      if variable == "`i'"
local i = `i' + 1
replace variable = "gai"      if variable == "`i'"
local i = `i' + 1
replace variable = "gpi"      if variable == "`i'"
local i = `i' + 1
replace variable = "gai_cond" if variable == "`i'"
local i = `i' + 1
replace variable = "gii_1"    if variable == "`i'"
local i = `i' + 1
replace variable = "gii_2"    if variable == "`i'"
local i = `i' + 1
replace variable = "gii_3"    if variable == "`i'"
local i = `i' + 1
replace variable = "gii_pca"  if variable == "`i'"

save "$TABLES\TABLE2", replace

** GENERATE TABLE 2

use "$TABLES\TABLE2", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\table2.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics, Language Variables\\ Female Immigrants, Married, Spouse Present, Aged 25-49}"
noisily display "\begin{tabular}{llccccr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "                   & Definition                           & Mean & S.d. & Min. & Max. & Obs. \\"
noisily display " \midrule"
local i = 1
noisily display "\texttt{SB}        & Sex-based                            &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "\texttt{NG}        & Number of genders                    &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "\texttt{GA}        & Gender assignment                    &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "\texttt{GP}        & Gender pronouns                      &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\\\"
local i = `i' + 1
local i = `i' + 1
local i = `i' + 1
local i = `i' + 1
noisily display "\texttt{Intensity} & \texttt{(GP + GA + NG) $ \times $ SB} &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table2} notes: The summary statistics are computed using sample weights (\texttt{perwt}) provided in the ACS \cite{ruggles2015}.}"
noisily display "\end{tablenotes}"
noisily display "\label{table2}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE 3: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** LOCALS

local controls        "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls        "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls        "`controls' i.dcimmig"
local controlshh      "nchild_l5 hhsize i.state"
local controlscob     "ratio_lfp_i_n lfp_cob nchild_cob tfr mig educyrs_cob"
local controlscob     "`controlscob' yr_sch_ratio comlang_ethno distcap gdpko_n lat" 
local controlscob     "`controlscob' lon gendist_weight i.cont"
local controls_std    "age_std age_sq_std i.year i.race hispan ageimmig_std"
local controls_std    "`controls_std' age_3034 age_3539 age_4044 age_4549"
local controls_std    "`controls_std' yrsusa_std student educyrs_std englvl_std"
local controls_std    "`controls_std' i.dcimmig"
local controlshh_std  "nchild_l5_std hhsize_std i.state"
local controlscob_std "ratio_lfp_i_n_std lfp_cob_std nchild_cob_std tfr_std"
local controlscob_std "`controlscob_std' mig_std educyrs_cob_std"
local controlscob_std "`controlscob_std' yr_sch_ratio_std comlang_ethno"
local controlscob_std "`controlscob_std' distcap_std gdpko_n_std lat_std" 
local controlscob_std "`controlscob_std' lon_std gendist_weight_std i.cont"

** CREATE STANDARDIZED VALUES

local variables "lfp sbi age age_sq ageimmig yrsusa educyrs"
local variables "`variables' englvl nchild_l5 hhsize ratio_lfp_i_n lfp_cob"
local variables "`variables' nchild_cob tfr mig educyrs_cob yr_sch_ratio"
local variables "`variables' distcap gdpko_n lat lon gendist_weight"
foreach v of local variables {
	egen `v'_std = std(`v') if (ratio_lfp_i_n != . & lfp_cob != . &          ///
								nchild_cob != . & tfr != . & mig != . &      ///
								educyrs_cob != . & yr_sch_ratio != .  &      ///
								comlang_ethno != . & gdpko_n != .)
}

local variables "lfp sbi"
foreach v of local variables {
	replace `v'_std = `v'                  /* indicators are not standardized */
}

** SUMMARY STATISTICS FOR LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)
summarize   lfp if county != 0 [aw=perwt]
scalar mean_lfp_7 = r(mean)

** REGRESSIONS

*** REGULAR REGRESSIONS

**** SPECIFICATION 1: NO CONTROLS

regress lfp sbi [pw=perwt], robust
parmest, saving(lfp_sbi_1, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 2: INDIVIDUAL AND HOUSEHOLD CONTROLS

regress lfp sbi `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_2, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 3: ADD COB CONTROLS, NO SB

regress lfp  `controlscob' `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_3, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 4: ADD COB CONTROLS, SB

regress lfp sbi `controlscob' `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_4, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 5: ADD COB FE

regress lfp sbi `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_sbi_5, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 6: ADD COB FE X DECADE OF MIGRATION FE

regress lfp sbi `controls' `controlshh' i.bpl##i.dcimmig [pw=perwt],         ///
	robust
parmest, saving(lfp_sbi_6, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 7: ADD COUNTY FE

regress lfp sbi `controls' `controlshh' i.bpl##i.dcimmig                     ///
		i.county_state if county != 0  [pw=perwt], robust
parmest, saving(lfp_sbi_7, replace) stars(0.1 0.05 0.01) es(N r2)			

*** STANDARDIZED REGRESSIONS FOR SPECIFICATIONS 3 and 4

regress lfp_std `controlscob_std' `controls_std' `controlshh_std'            ///
		[pw=perwt], robust
parmest, saving(lfp_std_sbi_std_3, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std `controlscob_std' `controls_std' `controlshh_std'    ///
		[pw=perwt], robust
parmest, saving(lfp_std_sbi_std_4, replace) stars(0.1 0.05 0.01) es(N r2)

*** RESIDUAL VARIANCE IN SB

sum sbi
scalar sbi_resvar_1 = r(Var)

regress sbi `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_2 = r(Var)
drop sbi_res

regress sbi `controlscob' `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_4 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' i.bpl [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_5 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' i.bpl##i.dcimmig [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_6 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' i.bpl##i.dcimmig i.county_state          ///
		if county != 0 [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_7 = r(Var)
drop sbi_res	

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 7 {

	use lfp_sbi_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi" | variable == "ratio_lfp_i_n" |                ///
			variable == "lfp_cob"
	
	save lfp_sbi_`i'_modif, replace
	erase lfp_sbi_`i'.dta
}

forvalues i = 3 / 4 {

	use lfp_std_sbi_std_`i', clear
	
	generate outcome  = "lfp_std"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_std" | variable == "ratio_lfp_i_n_std" ///
		  | variable == "lfp_cob_std"
	
	save lfp_std_sbi_std_`i'_modif, replace
	erase lfp_std_sbi_std_`i'.dta
}

*** APPEND

clear
forvalues i = 1 / 7 {
	append using lfp_sbi_`i'_modif
	cap append using lfp_std_sbi_std_`i'_modif
	erase lfp_sbi_`i'_modif.dta
	cap erase lfp_std_sbi_std_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .

replace  mean = mean_lfp if outcome == "lfp"

replace mean = mean_lfp_7 if (outcome == "lfp" & specification == "7")

forvalues i = 1 / 7 {

	cap replace resid_variance = sbi_resvar_`i' if specification == "`i'"
}

save "$TABLES\TABLE3", replace

** GENERATE TABLE 3

use "$TABLES\TABLE3", clear

set linesize 255

quietly {
capture log close
log using "$TABLES\table3.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Individual Level\\ Female Immigrants, Married, Spouse Present, 25-49 (2005-2015)}"
noisily display "\begin{tabular}{lccccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:           & \multicolumn{7}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-8}"
noisily display "                              & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\"
noisily display "\cmidrule(lr){2-8} "
noisily display "Sex-based                     &" %9.3fc b[1] "" stars[1] "&" %9.3fc b[2] "" stars[2] "&                            &" %9.3fc b[7] "" stars[7] "  &" %9.3fc b[13] "" stars[13] "&" %9.3fc b[14] "" stars[14] "&" %9.3fc b[15] "" stars[15] "\\"
noisily display "                              & [\rm" %9.3fc se[1] "]     & [\rm" %9.3fc se[2] "]     &                            & [\rm" %9.3fc se[7] "]       & [\rm" %9.3fc se[13] "]      & [\rm" %9.3fc se[14] "]      & [\rm" %9.3fc se[15] "]      \\"
noisily display "$ \beta $-coef.               &                           &                           &                            & " %9.3fc b[10] "            &                             &                             &                             \\\\" 
noisily display "COB LFP                       &                           &                           &" %9.3fc b[3] "" stars[3] " &" %9.3fc b[8] "" stars[8] "  &                             &                             &                             \\"
noisily display "                              &                           &                           & [\rm" %9.3fc se[3] "]      & [\rm" %9.3fc se[8] "]       &                             &                             &                             \\"
noisily display "$ \beta $-coef.               &                           &                           &  " %9.3fc b[5] "           & " %9.3fc b[11] "            &                             &                             &                             \\\\" 
noisily display "Ancestry LFP                  &                           &                           &" %9.3fc b[4] "" stars[4] " &" %9.3fc b[9] "" stars[9] "  &                             &                             &                             \\"
noisily display "                              &                           &                           &  [\rm" %9.3fc se[4] "]     & [\rm" %9.3fc se[9] "]       &                             &                             &                             \\"
noisily display "$ \beta $-coef.               &                           &                           & " %9.3fc b[6] "            & " %9.3fc b[12] "            &                             &                             &                             \\\\" 
noisily display "Respondent char. \\"
noisily display "\;\; Age                      & No & Yes &Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Race and ethnicity       & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Education                & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Years since immig.       & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Age at immig.            & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Decade of immig.         & No & Yes & Yes & Yes & Yes & Yes & Yes \\" 
noisily display "\;\; English prof.            & No & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "Household char. \\"
noisily display "\;\; Children aged $ < $ 5    & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; Household size           & No & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\;\; State                    & No & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "COB char. \\"
noisily display "\;\; Geography                & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; Fertility                & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; Migration rate           & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; Education                & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; GDP per capita           & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; Common language          & No & No & Yes & Yes & No & No & No \\"
noisily display "\;\; Genetic distance         & No & No & Yes & Yes & No & No & No \\\\"
noisily display "COB FE                        & No & No & No & No & Yes & Yes & Yes \\\\"
noisily display "COB $ \times $ decade mig. FE & No & No & No & No & No & Yes & Yes \\\\"
noisily display "County FE & No & No & No & No & No & No & Yes \\\\"
noisily display "Observations                  &" %9.0fc n[1] "&" %9.0fc n[2] "&" %9.0fc n[3] "&" %9.0fc n[7] "&" %9.0fc n[13] "&" %9.0fc n[14] "&" %9.0fc n[15] "\\"
noisily display "R$^2$                         &" %9.3fc r2[1] "&" %9.3fc r2[2] "&" %9.3fc r2[3] "&" %9.3fc r2[7] "&" %9.3fc r2[13] "&" %9.3fc r2[14] "&" %9.3fc r2[15] "\\\\"
noisily display "Mean                          &" %9.2fc mean[1] "&" %9.2fc mean[2] "&" %9.2fc mean[3] "&" %9.2fc mean[7] "&" %9.2fc mean[13] "&" %9.2fc mean[14] "&" %9.2fc mean[15] "\\"
noisily display "\texttt{SB} residual variance &" %9.3fc resid_variance[1] "&" %9.3fc resid_variance[2] "&&" %9.3fc resid_variance[7] "&" %9.3fc resid_variance[13] "&" %9.3fc resid_variance[14] "&" %9.3fc resid_variance[15] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table3} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. \textit{$ \beta $-coef.} denotes the coefficients from using standardized values of continuous variables in the regressions. \textit{COB} denotes \textit{country of birth}, \textit{LFP} denotes \textit{female labor participation}, and \textit{FE} denotes \textit{fixed effects}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table3}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE 4: LANGUAGE STRUCTURE AND HOUSEHOLD BARGAINING
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
keep if language_wals == language_wals_sp /* same language                    */

** LOCALS

local controls         "age age_sq i.year i.race hispan ageimmig age_3034"
local controls         "`controls' age_3539 age_4044 age_4549 yrsusa student"
local controls         "`controls' educyrs englvl i.dcimmig"
local controlshh       "nchild_l5 hhsize i.state"
local bargain          "age_gap nlabinc_gap"
local husband          "age_sq_sp i.race_sp hispan_sp ageimmig_sp yrsusa_sp"
local husband          "`husband' wks0_sp student_sp englvl_sp educyrs_sp"
local controls_std     "age_std age_sq_std i.year i.race hispan ageimmig_std"
local controls_std     "`controls_std' age_3034 age_3539 age_4044 age_4549"
local controls_std     "`controls_std' yrsusa_std student educyrs_std"
local controls_std     "`controls_std' englvl_std i.dcimmig"
local controlshh_std   "nchild_l5_std hhsize_std i.state"
local bargain_std      "age_gap_std nlabinc_gap_std"
local husband_std      "age_sq_sp_std i.race_sp hispan_sp ageimmig_sp_std"
local husband_std      "`husband_std' yrsusa_sp_std wks0_sp_std student_sp"
local husband_std      "`husband_std' englvl_sp_std educyrs_sp_std"
local controls_std_5   "age_std_5 age_sq_std_5 i.year i.race hispan"
local controls_std_5   "`controls_std_5' ageimmig_std_5 age_3034 age_3539"
local controls_std_5   "`controls_std_5' age_4044 age_4549 yrsusa_std_5"
local controls_std_5   "`controls_std_5' student educyrs_std_5 englvl_std_5"
local controls_std_5   "`controls_std_5' i.dcimmig"
local controlshh_std_5 "nchild_l5_std_5 hhsize_std_5 i.state"
local bargain_std_5    "age_gap_std_5 nlabinc_gap_std_5"
local husband_std_5    "age_sq_sp_std_5 i.race_sp hispan_sp ageimmig_sp_std_5"
local husband_std_5    "`husband_std_5' yrsusa_sp_std_5 wks0_sp_std_5"
local husband_std_5    "`husband_std_5' student_sp englvl_sp_std_5"
local husband_std_5    "`husband_std_5' educyrs_sp_std_5"

** CREATE STANDARDIZED VALUES

local variables "lfp sbi age age_sq ageimmig yrsusa educyrs"
local variables "`variables' englvl nchild_l5 hhsize age_gap nlabinc_gap"
local variables "`variables' age_sq_sp ageimmig_sp yrsusa_sp wks0_sp"
local variables "`variables' englvl_sp educyrs_sp"
foreach v of local variables {
	egen `v'_std = std(`v')
	egen `v'_std_5 = std(`v') if marbef == 1
}

local variables "lfp sbi"
foreach v of local variables {
	replace `v'_std = `v'                  /* indicators are not standardized */
}

** SUMMARY STATISTICS FOR LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)
summarize   lfp if marbef == 1 [aw=perwt]
scalar mean_lfp_5 = r(mean)

** REGRESSIONS

*** REGULAR REGRESSIONS

**** SPECIFICATION 1: INDIVIDUAL and HH CONTROLS, COB FE

regress lfp sbi `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_sbi_1, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 2: ADD HUSBAND CHARACTERISTICS AND BARGAINING MEASURES, NO SB

regress lfp `bargain' `controls' `controlshh' `husband' i.bpl                ///
		[pw=perwt], robust
parmest, saving(lfp_sbi_2, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 3: ADD BARGAINING MEASURES, SB

regress lfp sbi `bargain' `controls' `controlshh' `husband' i.bpl            ///
		[pw=perwt], robust
parmest, saving(lfp_sbi_3, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 4: ADD HUSBAND COB FE

regress lfp sbi `bargain' `controls' `controlshh' `husband' i.bpl            ///
		i.bpl_sp [pw=perwt], robust
parmest, saving(lfp_sbi_4, replace) stars(0.1 0.05 0.01) es(N r2)

***** SPECIFICATION 5: SAMPLE MARRIED BEFORE MIGRATION

regress lfp sbi `bargain' `controls' `controlshh' `husband' i.bpl            ///
		i.bpl_sp if marbef == 1 [pw=perwt], robust
parmest, saving(lfp_sbi_5, replace) stars(0.1 0.05 0.01) es(N r2)

***** SPECIFICATION 6: ADD BARGAINING X SB INTERACTIONS

regress lfp c.age_gap##sbi c.nlabinc_gap##sbi c.educ_gap##sbi                ///
		`controls' `controlshh' `husband' i.bpl i.bpl_sp [pw=perwt],         ///
		robust
parmest, saving(lfp_sbi_6, replace) stars(0.1 0.05 0.01) es(N r2)

*** STANDARDIZED REGRESSIONS FOR SPECIFICATIONS 2 TO 6

regress lfp_std `bargain_std' `controls_std' `controlshh_std'                ///
		`husband_std' i.bpl [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_2, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std `bargain_std' `controls_std' `controlshh_std'        ///
		`husband_std' i.bpl [pw=perwt],  ///
		robust
parmest, saving(lfp_std_sbi_std_3, replace) stars(0.1 0.05 0.01) es(N r2)		

regress lfp_std sbi_std `bargain_std' `controls_std' `controlshh_std'        ///
		`husband_std' i.bpl  ///
		i.bpl_sp [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_4, replace) stars(0.1 0.05 0.01) es(N r2)	

regress lfp_std sbi_std `bargain_std_5' `controls_std_5' `controlshh_std_5'  ///
		`husband_std_5' i.bpl i.bpl_sp if marbef == 1 [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_5, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std c.age_gap_std##sbi_std c.nlabinc_gap_std##sbi_std            ///
		`controls_std' `controlshh_std'          ///
		`husband_std' i.bpl i.bpl_sp [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_6, replace) stars(0.1 0.05 0.01) es(N r2)

*** RESIDUAL VARIANCE IN SB

regress sbi `controls' `controlshh' i.bpl [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_1 = r(Var)
drop sbi_res

regress sbi `bargain' `controls' `controlshh' `husband' i.bpl [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_3 = r(Var)
drop sbi_res

regress sbi `bargain' `controls' `controlshh' `husband' i.bpl i.bpl_sp       ///
		[pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_4 = r(Var)
drop sbi_res

regress sbi `bargain' `controls' `controlshh' `husband' i.bpl i.bpl_sp       ///
		if marbef == 1 [pw=perwt], robust
predict sbi_res if marbef == 1, residuals
sum sbi_res
scalar sbi_resvar_5 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 6 {

	use lfp_sbi_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi" | variable == "age_gap" |              ///
			variable == "nlabinc_gap"  |                             ///
			variable == "1.sbi" | variable == "1.sbi#c.age_gap" |    ///
			variable == "1.sbi#c.nlabinc_gap"
			
	save lfp_sbi_`i'_modif, replace
	erase lfp_sbi_`i'.dta
}

forvalues i = 2 / 6 {

	cap use lfp_std_sbi_std_`i', clear
	
	generate outcome  = "lfp_std"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_std" | variable == "age_gap_std" |      ///
			variable == "nlabinc_gap_std" |                          ///
			variable == "1.sbi_std"  |                               ///
			variable == "1.sbi_std#c.age_gap_std" |                  ///
			variable == "1.sbi_std#c.nlabinc_gap_std"  |             ///
			variable == "age_gap_std_5" | variable == "nlabinc_gap_std_5"
			
	save lfp_std_sbi_std_`i'_modif, replace
	erase lfp_std_sbi_std_`i'.dta
}

*** APPEND

clear
forvalues i = 1 / 6 {
	append using lfp_sbi_`i'_modif
	cap append using lfp_std_sbi_std_`i'_modif
	erase lfp_sbi_`i'_modif.dta
	cap erase lfp_std_sbi_std_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .

replace  mean = mean_lfp if outcome == "lfp"

forvalues i = 1 / 6 {

	cap replace resid_variance = sbi_resvar_`i' if specification == "`i'"
}

replace  mean = mean_lfp_5 if (outcome == "lfp" & specification == "5")

save "$TABLES\TABLE4", replace

** GENERATE TABLE 4

use "$TABLES\TABLE4", clear

set linesize 255

quietly {
capture log close
log using "$TABLES\table4.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Language and Household Bargaining\\ Same Language Married Couples (2005-2015)}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:                          & \multicolumn{6}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-7} "
noisily display "                                             & (1)                        & (2)                          & (3)                         & (4)                         & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7} "
noisily display "Sex-based                                    &" %9.3fc b[1] "" stars[1] " &                              &" %9.3fc b[6] "" stars[6] "  &" %9.3fc b[12] "" stars[12] "&" %9.3fc b[18] "" stars[18] "&" %9.3fc b[25] "" stars[25]  "\\"
noisily display "                                             & [\rm" %9.3fc se[1] "]      &                              & [\rm" %9.3fc se[6] "]       & [\rm" %9.3fc se[12] "]      & [\rm" %9.3fc se[18] "]      & [\rm" %9.3fc se[25] "]       \\"
noisily display "$ \beta $-coef.                              &                            &                              &" %9.3fc b[9] "              &" %9.3fc b[15] "             &" %9.3fc b[21] "             &" %9.3fc b[30] "            \\\\" 
noisily display "Age gap                                      &                            &" %9.3fc b[2] "" stars[2] "   &" %9.3fc b[7] "" stars[7] "  &" %9.3fc b[13] "" stars[13] "&" %9.3fc b[19] "" stars[19] "&" %9.3fc b[24] "" stars[24]  "\\"
noisily display "                                             &                            & [\rm" %9.3fc se[2] "]        & [\rm" %9.3fc se[7] "]       & [\rm" %9.3fc se[13] "]      & [\rm" %9.3fc se[19] "]      & [\rm" %9.3fc se[24] "]       \\" 
noisily display "$ \beta $-coef.                              &                            &" %9.3fc b[4] "               &" %9.3fc b[10] "             &" %9.3fc b[16] "             &" %9.3fc b[22] "             &" %9.3fc b[29] "            \\\\" 
noisily display "Non-labor income gap                         &                            &" %9.3fc b[3] "" stars[3] "   &" %9.3fc b[8] "" stars[8] "  &" %9.3fc b[14] "" stars[14] "&" %9.3fc b[20] "" stars[20] "&" %9.3fc b[27] "" stars[27]  "\\"
noisily display "                                             &                            & [\rm" %9.3fc se[3] "]        & [\rm" %9.3fc se[8] "]       & [\rm" %9.3fc se[14] "]      & [\rm" %9.3fc se[20] "]      & [\rm" %9.3fc se[27] "]       \\" 
noisily display "$ \beta $-coef.                              &                            &" %9.3fc b[5] "               &" %9.3fc b[11] "             &" %9.3fc b[17] "             &" %9.3fc b[23] "             &" %9.3fc b[32] "            \\\\" 
noisily display "Age gap $ \times $ \texttt{SB}               &                            &                              &                             &                             &                             & " %9.3fc b[26] "" stars[26] "\\"
noisily display "                                             &                            &                              &                             &                             &                             & [\rm" %9.3fc se[26] "]       \\" 
noisily display "$ \beta $-coef.                              &                            &                              &                             &                             &                             &" %9.3fc b[31] "            \\\\" 
noisily display "Non-labor income gap  $ \times $ \texttt{SB} &                            &                              &                             &                             &                             &" %9.3fc b[28] "" stars[28]  "\\"
noisily display "                                             &                            &                              &                             &                             &                             & [\rm" %9.3fc se[28] "]       \\" 
noisily display "$ \beta $-coef.                              &                            &                              &                             &                             &                             &" %9.3fc b[33] "            \\\\" 
noisily display "Respondent char.                             & Yes                        & Yes                          & Yes                         & Yes                         & Yes                         & Yes                          \\"
noisily display "Household char.                              & Yes                        & Yes                          & Yes                         & Yes                         & Yes                         & Yes                          \\"
noisily display "Respondent COB FE                            & Yes                        & Yes                          & Yes                         & Yes                         & Yes                         & Yes                        \\\\"
noisily display "Husband char.                                & No                         & Yes                          & Yes                         & Yes                         & Yes                         & Yes                          \\"
noisily display "Husband COB FE                               & No                         & No                           & No                          & Yes                         & Yes                         & Yes                        \\\\"
noisily display "Sample mar. before mig.                      & No                         & No                           & No                          & No                          & Yes                         & No                         \\\\"
noisily display "Observations                                 &" %9.0fc n[1] "             &" %9.0fc n[2] "               &" %9.0fc n[8] "              &" %9.0fc n[16] "             &" %9.0fc n[23] "             &" %9.0fc n[32]               "\\"
noisily display "R$^2$                                        &" %9.3fc r2[1] "            &" %9.3fc r2[2] "              &" %9.3fc r2[8] "             &" %9.3fc r2[16] "            &" %9.3fc r2[23] "            &" %9.3fc r2[32]            "\\\\"
noisily display "Mean                                         &" %9.2fc mean[1] "          &" %9.2fc mean[2] "            &" %9.2fc mean[8] "           &" %9.2fc mean[12] "          &" %9.2fc mean[18] "          &" %9.2fc mean[24]            "\\"
noisily display "\texttt{SB} residual variance                &" %9.3fc resid_variance[1] "&                              &" %9.3fc resid_variance[8] " &" %9.3fc resid_variance[16] "&" %9.3fc resid_variance[23] "&" %9.3fc resid_variance[24] " \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table4} notes: The estimates are computed using sample weights (\texttt{perwt}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table4}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE 5: LINGUISTIC HETEROGENEITY IN THE HOUSEHOLD
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
drop if bpl_sp == 0                       /* drop husbands born in US         */
drop if citizen_sp == 0                   /* drop husbands US citizens        */
drop if (sbi_sp != 0 & sbi_sp != 1)       /* spouse variable present          */

** LOCALS

local controls     "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls     "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls     "`controls' i.dcimmig sp_eng"
local controlshh   "nchild_l5 hhsize i.state"
local husband      "age_sp age_sq_sp i.race_sp hispan_sp ageimmig_sp yrsusa_sp"
local husband      "`husband' nlabinc_sp wks0_sp educyrs_sp student_sp englvl_sp"
local controlscob  "ratio_lfp_i_n lfp_cob nchild_cob tfr mig educyrs_cob"
local controlscob  "`controlscob' yr_sch_ratio comlang_ethno distcap gdpko_n lat" 
local controlscob  "`controlscob' lon gendist_weight i.cont"
local controlsfull "`controls' `controlshh' `husband'"

** SUMMARY STATISTICS OF LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)

** REGRESSIONS

*** SPECIFICATION 1: WIFE'S LANGUAGE

regress lfp sbi_same sbi_dif `controlsfull' [pw=perwt], robust
parmest, saving(lfp_1, replace) stars(0.1 0.05 0.01) es(N r2)

*** SPECIFICATION 2: HUSBAND'S LANGUAGE

regress lfp sbi_same sbi_sp_dif `controlsfull' [pw=perwt], robust
parmest, saving(lfp_2, replace) stars(0.1 0.05 0.01) es(N r2)

*** SPECIFICATION 3: BOTH SPOUSES' LANGUAGE

regress lfp sbi_same sbi_dif sbi_sp_dif `controlsfull' [pw=perwt], robust 
parmest, saving(lfp_3, replace) stars(0.1 0.05 0.01) es(N r2)

*** SPECIFICATION 4: WIFE'S COB CHARACTERISTICS

regress lfp sbi_same sbi_dif sbi_sp_dif `controlsfull' `controlscob'         ///
		[pw=perwt], robust 
parmest, saving(lfp_4, replace) stars(0.1 0.05 0.01) es(N r2)

*** SPECIFICATION 5: WIFE'S COB FE

regress lfp sbi_same sbi_dif sbi_sp_dif `controlsfull' i.bpl                 ///
		[pw=perwt], robust 
parmest, saving(lfp_5, replace) stars(0.1 0.05 0.01) es(N r2)	

** RESIDUAL VARIANCE IN SB

regress sbi `controlsfull' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_1 = r(Var)
drop sbi_res

regress sbi `controlsfull' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_2 = r(Var)
drop sbi_res

regress sbi `controlsfull' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_3 = r(Var)
drop sbi_res

regress sbi `controlsfull' `controlscob' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_4 = r(Var)
drop sbi_res

regress sbi `controlsfull' i.bpl  [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_5 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 5 {

	use lfp_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_same" | variable == "sbi_dif" |             ///
			variable == "sbi_sp_dif"
	
	save lfp_`i'_modif, replace
	erase lfp_`i'.dta
}

*** APPEND

clear
	forvalues i = 1 / 5 {
		append using lfp_`i'_modif
		erase lfp_`i'_modif.dta
	}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .

replace  mean = mean_lfp if outcome == "lfp"

forvalues i = 1 / 5 {

	cap replace resid_variance = sbi_resvar_`i' if specification == "`i'"
}	

save "$TABLES\TABLE5", replace

** GENERATE TABLE 5

use "$TABLES\TABLE5", clear

set linesize 255

quietly {
capture log close
log using "$TABLES\table5.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Linguistic Heterogeneity in the Household\\ Immigrant Households (2005-2015)}"
noisily display "\begin{tabular}{lccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:                      & \multicolumn{5}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-6} "
noisily display "                                         & (1)                        & (2)                         & (3)                        & (4)                         & (5)                           \\"
noisily display "\cmidrule(lr){2-6} "
noisily display "Same $ \times $ wife's sex-based         &" %9.3fc b[1] "" stars[1] " &" %9.3fc b[3] "" stars[3] "  &" %9.3fc b[5] "" stars[5]  "&" %9.3fc b[8] "" stars[8] "  &" %9.3fc b[11] "" stars[11]   "\\"
noisily display "                                         & [\rm" %9.3fc se[1] "]      & [\rm" %9.3fc se[3] "]       & [\rm" %9.3fc se[5] "]      & [\rm" %9.3fc se[8] "]       & [\rm" %9.3fc se[11] "]      \\\\"
noisily display "Different $ \times $ wife's sex-based    &" %9.3fc b[2] "" stars[2] " &                             &" %9.3fc b[6] "" stars[6] " &" %9.3fc b[9] "" stars[9] "  &" %9.3fc b[12] "" stars[12]   "\\"
noisily display "                                         &[\rm" %9.3fc se[2] "]       &                             & [\rm" %9.3fc se[6] "]      & [\rm" %9.3fc se[9] "]       & [\rm" %9.3fc se[12] "]      \\\\" 
noisily display "Different $ \times $ husband's sex-based &                            &" %9.3fc b[4] "" stars[4] "  &" %9.3fc b[7] "" stars[7] " &" %9.3fc b[10] "" stars[10] "&" %9.3fc b[13] "" stars[13]   "\\"
noisily display "                                         &                            & [\rm" %9.3fc se[4] "]       & [\rm" %9.3fc se[7] "]      & [\rm" %9.3fc se[10] "]      & [\rm" %9.3fc se[13] "]      \\\\" 
noisily display "Respondent char.                         & Yes                        & Yes                         & Yes                        & Yes                         & Yes                           \\"
noisily display "Household char.                          & Yes                        & Yes                         & Yes                        & Yes                         & Yes                           \\"
noisily display "Husband char.                            & Yes                        & Yes                         & Yes                        & Yes                         & Yes                         \\\\"
noisily display "Respondent COB char.                     & No                         & No                          & No                         & Yes                         & No                            \\"
noisily display "Respondent COB FE                        & No                         & No                          & No                         & No                          & Yes                         \\\\"
noisily display "Observations                             &" %9.0fc n[1] "             &" %9.0fc n[3] "              &" %9.0fc n[5] "             &" %9.0fc n[8] "              &" %9.0fc n[11]                "\\"
noisily display "R$^2$                                    &" %9.3fc r2[1] "            &" %9.3fc r2[3] "             &" %9.3fc r2[5] "            &" %9.3fc r2[8] "             &" %9.3fc r2[11]             "\\\\"
noisily display "Mean                                     &" %9.2fc mean[1] "          &" %9.2fc mean[3] "           &" %9.2fc mean[5] "          &" %9.2fc mean[8] "           &" %9.2fc mean[11]             "\\"
noisily display "\texttt{SB} residual variance            &" %9.3fc resid_variance[1] "& " %9.3fc resid_variance[3] "&" %9.3fc resid_variance[5] "&" %9.3fc resid_variance[8] " &" %9.3fc resid_variance[11]  " \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table5} notes: The estimates are computed using sample weights (\texttt{perwt}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table5}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE 6: LANGUAGE AND SOCIAL INTERACTIONS
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
drop if county == 0                       /* drop non-identified counties     */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"

local controls_std    "age_std age_sq_std i.year i.race hispan ageimmig_std"
local controls_std    "`controls_std' age_3034 age_3539 age_4044 age_4549"
local controls_std    "`controls_std' yrsusa_std student educyrs_std englvl_std"
local controls_std    "`controls_std' i.dcimmig"
local controlshh_std  "nchild_l5_std hhsize_std i.state"

** CREATE STANDARDIZED VALUES

local variables "lfp sbi age age_sq ageimmig yrsusa educyrs"
local variables "`variables' englvl nchild_l5 hhsize sh_bpl_w sh_lang_w"
foreach v of local variables {
	egen `v'_std = std(`v')
}

local variables "lfp sbi"
foreach v of local variables {
	replace `v'_std = `v'                  /* indicators are not standardized */
}

** SUMMARY STATISTICS OF LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)

** REGRESSIONS

*** REGULAR REGRESSIONS

**** SPECIFICATION 1: COB DENSITY

regress lfp sh_bpl_w `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_1, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 2: ADD SB AND INTERACTION

regress lfp c.sh_bpl_w##sbi `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_2, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 3: LANGUAGE DENSITY

regress lfp sh_lang_w `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_3, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 4: ADD SB AND INTERACTION

regress lfp c.sh_lang_w##sbi `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_4, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 5: BOTH COB AND LANGUAGE DENSITIES

regress lfp c.sh_bpl_w##sbi c.sh_lang_w##sbi `controls' `controlshh'         ///
		[pw=perwt], robust
parmest, saving(lfp_sbi_5, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 6: ADD COB FE

regress lfp c.sh_bpl_w##sbi c.sh_lang_w##sbi `controls' `controlshh'         ///
		i.bpl [pw=perwt], robust
parmest, saving(lfp_sbi_6, replace) stars(0.1 0.05 0.01) es(N r2)

*** STANDARDIZED REGRESSIONS

regress lfp_std sh_bpl_w_std `controls_std' `controlshh_std' [pw=perwt],     ///
		robust
parmest, saving(lfp_std_sbi_std_1, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std c.sh_bpl_w_std##sbi_std `controls_std' `controlshh_std'      ///
		[pw=perwt], robust
parmest, saving(lfp_std_sbi_std_2, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sh_lang_w_std `controls_std' `controlshh_std' [pw=perwt],    ///
		robust
parmest, saving(lfp_std_sbi_std_3, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std c.sh_lang_w_std##sbi_std `controls_std' `controlshh_std'     ///
		[pw=perwt], robust
parmest, saving(lfp_std_sbi_std_4, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std c.sh_bpl_w_std##sbi_std c.sh_lang_w_std##sbi_std             ///
		`controls_std' `controlshh_std' [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_5, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std c.sh_bpl_w_std##sbi_std c.sh_lang_w_std##sbi_std             ///
		`controls_std' `controlshh_std' i.bpl [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_6, replace) stars(0.1 0.05 0.01) es(N r2)	

*** RESIDUAL VARIANCE IN SB

regress sbi `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_2 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_4 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_5 = r(Var)
drop sbi_res

regress sbi `controls' `controlshh' i.bpl [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_6 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 6 {

	use lfp_sbi_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi"              | variable == "sh_bpl_w" |        ///
			variable == "sh_lang_w"        | variable == "1.sbi"    |        ///
			variable == "1.sbi#c.sh_bpl_w" | variable == "1.sbi#c.sh_lang_w"
	
	save lfp_sbi_`i'_modif, replace
	erase lfp_sbi_`i'.dta
}

foreach i of numlist 1 / 6 {

	use lfp_std_sbi_std_`i', clear
	
	generate outcome  = "lfp_std"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_std"         | variable == "sh_bpl_w_std" |     ///
			variable == "sh_lang_w_std"   | variable == "1.sbi_std"    |     ///
			variable == "1.sbi_std#c.sh_bpl_w_std" |                         ///
			variable == "1.sbi_std#c.sh_lang_w_std"
	
	save lfp_std_sbi_std_`i'_modif, replace
	erase lfp_std_sbi_std_`i'.dta
}

*** APPEND

clear
forvalues i = 1 / 6 {
	append using lfp_sbi_`i'_modif
	append using lfp_std_sbi_std_`i'_modif
	erase lfp_sbi_`i'_modif.dta
	erase lfp_std_sbi_std_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .
replace  mean = mean_lfp if outcome == "lfp"
	
forvalues i = 1 / 6 {
	cap replace resid_variance = sbi_resvar_`i' if specification == "`i'"
}
		
save "$TABLES\TABLE6", replace

** GENERATE TABLE 6

use "$TABLES\TABLE6", clear

set linesize 255

quietly {
capture log close
log using "$TABLES\table6.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Language and Social Interactions\\ Respondents In Identifiable Counties (2005-2015)}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:                     & \multicolumn{6}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-7} "
noisily display "                                        & (1)                       & (2)                        & (3)                          & (4)                         & (5)                         & (6)                           \\"
noisily display "\cmidrule(lr){2-7} "
noisily display "Sex-based                               &                           &" %9.3fc b[4] "" stars[4] " &                              &" %9.3fc b[12] "" stars[12] "&" %9.3fc b[18] "" stars[18] "&" %9.3fc b[28] "" stars[28]   "\\"
noisily display "                                        &                           & [\rm" %9.3fc se[4] "]      &                              & [\rm" %9.3fc se[12] "]      & [\rm" %9.3fc se[18] "]      & [\rm" %9.3fc se[28] "]        \\"
noisily display "$ \beta $-coef.                         &                           &" %9.3fc b[7] "             &                              &" %9.3fc b[15] "             &" %9.3fc b[23] "             &" %9.3fc b[33] "             \\\\" 
noisily display "Density COB                             &" %9.3fc b[1] "" stars[1] "&" %9.3fc b[3] "" stars[3] " &                              &                             &" %9.3fc b[17] "" stars[17] "&" %9.3fc b[27] "" stars[27]   "\\"
noisily display "                                        & [\rm" %9.3fc se[1] "]     & [\rm" %9.3fc se[3] "]      &                              &                             & [\rm" %9.3fc se[17] "]      & [\rm" %9.3fc se[27] "]        \\" 
noisily display "$ \beta $-coef.                         &" %9.3fc b[2] "            &" %9.3fc b[6] "             &                              &                             &" %9.3fc b[22] "             &" %9.3fc b[32] "             \\\\" 
noisily display "Density COB $ \times $ \texttt{SB}      &                           &" %9.3fc b[5] "" stars[5] " &                              &                             &" %9.3fc b[19] "" stars[19] "&" %9.3fc b[29] "" stars[29]   "\\"
noisily display "                                        &                           & [\rm" %9.3fc se[5] "]      &                              &                             & [\rm" %9.3fc se[19] "]      & [\rm" %9.3fc se[29] "]        \\" 
noisily display "$ \beta $-coef.                         &                           &" %9.3fc b[8] "             &                              &                             &" %9.3fc b[24] "             &" %9.3fc b[34] "             \\\\" 
noisily display "Density language                        &                           &                            &" %9.3fc b[9] "" stars[9]   " &" %9.3fc b[11] "" stars[11] "&" %9.3fc b[20] "" stars[20] "&" %9.3fc b[30] "" stars[30]   "\\"
noisily display "                                        &                           &                            & [\rm" %9.3fc se[9] "]        & [\rm" %9.3fc se[11] "]      & [\rm" %9.3fc se[20] "]      & [\rm" %9.3fc se[30] "]        \\" 
noisily display "$ \beta $-coef.                         &                           &                            &" %9.3fc b[10] "              &" %9.3fc b[14] "             &" %9.3fc b[25] "             &" %9.3fc b[35] "             \\\\" 
noisily display "Density language $ \times $ \texttt{SB} &                           &                            &                              &" %9.3fc b[13] "" stars[13] "&" %9.3fc b[21] "" stars[21] "&" %9.3fc b[31] "" stars[31]   "\\"
noisily display "                                        &                           &                            &                              & [\rm" %9.3fc se[13] "]      & [\rm" %9.3fc se[21] "]      & [\rm" %9.3fc se[31] "]        \\" 
noisily display "$ \beta $-coef.                         &                           &                            &                              &" %9.3fc b[16] "             &" %9.3fc b[26] "             &" %9.3fc b[36] "             \\\\" 
noisily display "Respondent char.                        & Yes                       & Yes                        & Yes                          & Yes                         & Yes                         & Yes                           \\"
noisily display "Household char.                         & Yes                       & Yes                        & Yes                          & Yes                         & Yes                         & Yes                           \\"
noisily display "Respondent COB FE                       & No                        & No                         & No                           & No                          & No                          & Yes                         \\\\"
noisily display "Observations                            &" %9.0fc n[1] "            &" %9.0fc n[3] "             &" %9.0fc n[9] "               &" %9.0fc n[11] "             &" %9.0fc n[17] "             &" %9.0fc n[27]                "\\"
noisily display "R$^2$                                   &" %9.3fc r2[1] "           &" %9.3fc r2[3] "            &" %9.3fc r2[9] "              &" %9.3fc r2[11] "            &" %9.3fc r2[17] "            &" %9.3fc r2[27]             "\\\\"
noisily display "Mean                                    &" %9.2fc mean[1] "         &" %9.2fc mean[3] "          &" %9.2fc mean[9] "            &" %9.2fc mean[11] "          &" %9.2fc mean[17] "          &" %9.2fc mean[27]             "\\"
noisily display "\texttt{SB} residual variance           &                           &" %9.3fc resid_variance[3] "&                              &" %9.3fc resid_variance[11] "&" %9.3fc resid_variance[17] "&" %9.3fc resid_variance[27]  " \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table6} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table6}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE 7: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION ADDITIONAL OUTCOMES
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"
local outcomes    "lfp emp wks0 wks hrs0 hrs"
local language    "sbi ngi gai gpi gii_3"

** SUMMARY STATISTICS OF LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)

** REGRESSIONS

foreach l of local language {
	foreach o of local outcomes {

		regress `o' `l' `controls' `controlshh' i.bpl [pw=perwt], robust
		parmest, saving(`o'_`l'_5, replace) stars(0.1 0.05 0.01) es(N r2)
		
	}
}

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

foreach l of local language {
	foreach o of local outcomes {
		
			use `o'_`l'_5, clear
			
			generate outcome  = "`o'"
			generate specification = "5"
			rename es_1 n
			rename es_2 r2
			rename parm variable
			rename stderr se
			rename estimate b
			
			order outcome specification variable, first
			
			keep if variable == "`l'"
			
			save `o'_`l'_5_modif, replace
			erase `o'_`l'_5.dta
	}
}

*** APPEND

foreach l of local language {
	clear
	foreach o of local outcomes {
			append using `o'_`l'_5_modif
			erase `o'_`l'_5_modif.dta
	}
	save TABLE7_`l'_rep, replace
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

foreach l of local language {
	use TABLE7_`l'_rep, clear
	
	generate mean = .

	foreach o of local outcomes {

		replace  mean = mean_`o' if outcome == "`o'"
	}
	
	save estimates_TABLE7_`l'_rep, replace
	erase TABLE7_`l'_rep.dta
}

clear
foreach l of local language {
	append using estimates_TABLE7_`l'_rep
}

generate order = 0
replace order = 1 if outcome == "emp"
replace order = 2 if outcome == "wks0"
replace order = 4 if outcome == "wks"
replace order = 3 if outcome == "hrs0"
replace order = 5 if outcome == "hrs"

generate order_lang = 1
replace order_lang  = 2 if variable == "sbi"
replace order_lang  = 3 if variable == "ngi"
replace order_lang  = 4 if variable == "gai"
replace order_lang  = 5 if variable == "gpi"
replace order_lang  = 6 if variable == "gii_3"
sort order_lang order

save "$TABLES\TABLE7", replace

foreach l of local language {
	erase estimates_TABLE7_`l'_rep.dta
}

** GENERATE TABLE 7

use "$TABLES\TABLE7", clear

set linesize 255

quietly {
capture log close
log using "$TABLES\table7.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Additional Outcomes \\ Replication of Column 5 of Table \ref{table_indiv_sb}, All Language Variables}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & \multicolumn{2}{c}{Extensive margin} & \multicolumn{4}{c}{Intensive margins} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){2-3}  \cmidrule(l{2pt}r{2pt}){4-7} "
noisily display " & \multicolumn{2}{c}{} & \multicolumn{2}{c}{Including zeros} & \multicolumn{2}{c}{Excluding zeros} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){4-5} \cmidrule(l{2pt}r{2pt}){6-7} "
noisily display "Dependent variable:  & LFP & Employed & Weeks & Hours & Weeks & Hours \\"
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel A. Sex-based} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 1
noisily display "\texttt{SB} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel B. Number of genders} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 7
noisily display "\texttt{NG} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel C. Gender assignment} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 13
noisily display "\texttt{GA} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel D. Gender pronouns} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 19
noisily display "\texttt{GP} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel E. \texttt{Intensity}} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 25
noisily display "\texttt{Intensity} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\\\"
noisily display "Respondent char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Household char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Respondent COB FE & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.1fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.1fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{table7} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{table7}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}


timer off 1 /* 2,524 sec*/

********************
* PART 2: APPENDIX *
********************

timer on 2

* TABLE C1: LANGUAGE DISTRIBUTION BY FAMILY IN THE REGRESSION SAMPLE
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** COLLAPSE BY COB AND LANGUAGE

keep language_wals genus_wals-gii_pca
generate count = 1
generate total = _N
collapse (sum) count (mean) total, by(language_wals-gii_pca)
keep language_wals-family_wals count total
generate percent = (count / total) * 100
drop total
sort family_wals genus_wals percent

/* Table C1 is then generated manually */
}

* TABLE C2: SUMMARY STATISTICS, NO SAMPLE SELECTION
{
** LOAD THE DATA AND APPEND ORIGINAL DATASET

use REH_noselection.dta, clear
generate sample = 1

append using REH_final.dta
replace sample = 0 if sample == .

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** SUMMARY STATISTICS, INDIVIDUAL CHARACTERISTICS

local variables "age yrsusa ageimmig student educyrs educ4"
local variables "`variables' educ2 educ3 educ1 race1 race2 race4 race3 hispan"
local variables "`variables' speakeng1 speakeng4 speakeng3 speakeng2"
local variables "`variables' lfp emp wks wks0 hrs hrs0 incwage inctot"

foreach v of local variables {

	/* summary statistics */

	summarize `v' if sample == 1 [aw=perwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* test differences between samples */
	
	ttest `v', by(sample)
	scalar diff_`v' = r(mu_1) - r(mu_2)
	scalar pval_`v' = r(p)
}

** SUMMARY STATISTICS, HOUSEHOLD CHARACTERISTICS

local variables "timemarr nchild_l5 nchild hhsize hhinc"

foreach v of local variables {

	/* summary statistics */

	summarize `v' if sample == 1 [aw=hhwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* test differences between samples */
	
	ttest `v', by(sample)
	scalar diff_`v' = r(mu_1) - r(mu_2)
	scalar pval_`v' = r(p)
}	

** DATASET OF SUMMARY STATISTICS AND ESTIMATES

matrix TABLEC2 = J(31,10,.)

local variables "age yrsusa ageimmig student educyrs educ4"
local variables "`variables' educ2 educ3 educ1 race1 race2 race4 race3 hispan"
local variables "`variables' speakeng1 speakeng4 speakeng3 speakeng2"
local variables "`variables' lfp emp wks wks0 hrs hrs0 incwage inctot"
local variables "`variables' timemarr nchild_l5 nchild hhsize hhinc"

local j = 0
foreach v of local variables {
	local j = `j' + 1
		
    matrix TABLEC2[`j',1] = `j'                  /* variable name              */
    matrix TABLEC2[`j',3] = mean_`v'             /* mean                       */
	matrix TABLEC2[`j',4] = sd_`v'               /* s.d.                       */
	matrix TABLEC2[`j',5] = min_`v'              /* min                        */
	matrix TABLEC2[`j',6] = max_`v'              /* max                        */
	matrix TABLEC2[`j',7] = n_`v'                /* observations               */
	matrix TABLEC2[`j',8] = diff_`v'             /* difference between samples */
	matrix TABLEC2[`j',9] = pval_`v'             /* p-value                    */
}

drop _all
svmat TABLEC2

rename TABLEC21  variable
rename TABLEC22  level
rename TABLEC23  mean
rename TABLEC24  sd
rename TABLEC25  min
rename TABLEC26  max
rename TABLEC27  n
rename TABLEC28  estimate
rename TABLEC29  p
rename TABLEC210 stars

foreach v of varlist variable-level stars {
	tostring `v', replace
}

local i = 1
replace variable = "age"        if variable == "`i'"
local i = `i' + 1
replace variable = "yrsusa"     if variable == "`i'"
local i = `i' + 1
replace variable = "ageimmig"   if variable == "`i'"
local i = `i' + 1
replace variable = "student"    if variable == "`i'"
local i = `i' + 1
replace variable = "educyrs"    if variable == "`i'"
local i = `i' + 1
replace variable = "educ4"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ2"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ3"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race2"      if variable == "`i'"
local i = `i' + 1
replace variable = "race4"      if variable == "`i'"
local i = `i' + 1
replace variable = "race3"      if variable == "`i'"
local i = `i' + 1
replace variable = "hispan"     if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng1"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng4"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng3"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng2"  if variable == "`i'"
local i = `i' + 1
replace variable = "lfp"        if variable == "`i'"
local i = `i' + 1
replace variable = "emp"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks0"       if variable == "`i'"
local i = `i' + 1
replace variable = "hrs"        if variable == "`i'"
local i = `i' + 1
replace variable = "hrs0"       if variable == "`i'"
local i = `i' + 1
replace variable = "incwage"    if variable == "`i'"
local i = `i' + 1
replace variable = "inctot"     if variable == "`i'"
local i = `i' + 1
replace variable = "timemarr"   if variable == "`i'"
local i = `i' + 1
replace variable = "nchild_l5"  if variable == "`i'"
local i = `i' + 1
replace variable = "nchild"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhsize"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhinc"      if variable == "`i'"

replace level = "respondent"
replace level = "household" if variable == "hhsize" | variable == "hhinc" |  ///
						   variable == "nchild_l5" | variable == "timemarr"  ///
						   | variable == "nchild"

replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1

save "$TABLES\TABLEC2", replace

** GENERATE TABLE C2

use "$TABLES\TABLEC2", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec2.tex", text replace
noisily display "\begin{table}[!h]"
noisily display "\centering"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics, No Sample Selection \\ Replication of Table \ref{table1}}"
noisily display "\begin{tabular}{lccccrr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "                          & Mean & S.d. & Min. & Max. & Obs. & Difference \\"
noisily display " \midrule"
noisily display "                          & \multicolumn{6}{c}{A. Individual characteristics} \\"
noisily display " \cmidrule(lr){2-7}\\"
local i = 1
noisily display "Age    &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Years since immigration &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Age at immigration &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Educational Attainment \\"
noisily display "\;\; Current student &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Years of schooling &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; No schooling &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Elementary &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; High school &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; College &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Race and ethnicity \\"
noisily display "\;\; Asian &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Black &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; White &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Other &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Hispanic &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Ability to speak English \\"
noisily display "\;\; Not at all &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Not well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Very well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Labor market outcomes \\"
noisily display "\;\; Labor participant &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Employed &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (excl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (incl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (excl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (incl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Labor income (thds.) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display " \cmidrule(lr){2-7}"
noisily display "                          & \multicolumn{6}{c}{B. Household characteristics} \\"
noisily display " \cmidrule(lr){2-7} \\"
local i = `i' + 2
noisily display "Years since married &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children aged $ < $ 5 &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household size &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household income (thds.) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec2} notes: The summary statistics are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}, except those for household characteristics, which are computed using household weights (\texttt{HHWT}). The last column reports the difference in means between the uncorrected sample and the regression sample, along with stars indicating the significance level of a t-test of differences in means. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec2}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C3: SUMMARY STATISTICS, HUSBANDS
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* husbands attached to wives       */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** SUMMARY STATISTICS, INDIVIDUAL CHARACTERISTICS

local variables "age_sp yrsusa_sp ageimmig_sp student_sp educyrs_sp educ_sp4"
local variables "`variables' educ_sp2 educ_sp3 educ_sp1 race_sp1 race_sp2"
local variables "`variables' race_sp4 race_sp3 hispan_sp speakeng_sp1"
local variables "`variables' speakeng_sp4 speakeng_sp3 speakeng_sp2 lfp_sp"
local variables "`variables' emp_sp wks_sp wks0_sp hrs_sp hrs0_sp incwage_sp"
local variables "`variables' inctot_sp"

foreach v of local variables {

	/* summary statistics */

	summarize `v' [aw=perwt_sp]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* SB1 - SB0 */
	
	regress `v' sbi_sp [pw=perwt_sp], robust
	parmest, saving(`v', replace)
}

** SUMMARY STATISTICS, HOUSEHOLD CHARACTERISTICS

local variables "timemarr nchild_l5 nchild hhsize hhinc"

foreach v of local variables {

	/* summary statistics */

	summarize `v' [aw=hhwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* SB1 - SB0 */
	
	regress `v' sbi_sp [pw=hhwt], robust
	parmest, saving(`v', replace)
}	

** DATASET OF SUMMARY STATISTICS AND ESTIMATES

matrix TABLEC3 = J(31,10,.)

local variables "age_sp yrsusa_sp ageimmig_sp student_sp educyrs_sp educ_sp4"
local variables "`variables' educ_sp2 educ_sp3 educ_sp1 race_sp1 race_sp2"
local variables "`variables' race_sp4 race_sp3 hispan_sp speakeng_sp1"
local variables "`variables' speakeng_sp4 speakeng_sp3 speakeng_sp2 lfp_sp"
local variables "`variables' emp_sp wks_sp wks0_sp hrs_sp hrs0_sp incwage_sp"
local variables "`variables' inctot_sp"
local variables "`variables' timemarr nchild_l5 nchild hhsize hhinc"

local j = 0
foreach v of local variables {
	local j = `j' + 1
	
	use `v', clear
	
	matrix TABLEC3[`j',1] = `j'                        /* variable name        */
	matrix TABLEC3[`j',3] = mean_`v'                   /* mean                 */
	matrix TABLEC3[`j',4] = sd_`v'                     /* s.d.                 */
	matrix TABLEC3[`j',5] = min_`v'                    /* min                  */
	matrix TABLEC3[`j',6] = max_`v'                    /* max                  */
	matrix TABLEC3[`j',7] = n_`v'                      /* observations         */
	matrix TABLEC3[`j',8] = estimate[1]                /* estimates on SBI = 1 */
	matrix TABLEC3[`j',9] = p[1]                       /* p-value              */
	
	erase `v'.dta
}

drop _all
svmat TABLEC3

rename TABLEC31  variable
rename TABLEC32  level
rename TABLEC33  mean
rename TABLEC34  sd
rename TABLEC35  min
rename TABLEC36  max
rename TABLEC37  n
rename TABLEC38  estimate
rename TABLEC39  p
rename TABLEC310 stars

foreach v of varlist variable-level stars {
	tostring `v', replace
}

local i = 1
replace variable = "age"        if variable == "`i'"
local i = `i' + 1
replace variable = "yrsusa"     if variable == "`i'"
local i = `i' + 1
replace variable = "ageimmig"   if variable == "`i'"
local i = `i' + 1
replace variable = "student"    if variable == "`i'"
local i = `i' + 1
replace variable = "educyrs"    if variable == "`i'"
local i = `i' + 1
replace variable = "educ4"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ2"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ3"      if variable == "`i'"
local i = `i' + 1
replace variable = "educ1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race1"      if variable == "`i'"
local i = `i' + 1
replace variable = "race2"      if variable == "`i'"
local i = `i' + 1
replace variable = "race4"      if variable == "`i'"
local i = `i' + 1
replace variable = "race3"      if variable == "`i'"
local i = `i' + 1
replace variable = "hispan"     if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng1"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng4"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng3"  if variable == "`i'"
local i = `i' + 1
replace variable = "speakeng2"  if variable == "`i'"
local i = `i' + 1
replace variable = "lfp"        if variable == "`i'"
local i = `i' + 1
replace variable = "emp"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks"        if variable == "`i'"
local i = `i' + 1
replace variable = "wks0"       if variable == "`i'"
local i = `i' + 1
replace variable = "hrs"        if variable == "`i'"
local i = `i' + 1
replace variable = "hrs0"       if variable == "`i'"
local i = `i' + 1
replace variable = "incwage"    if variable == "`i'"
local i = `i' + 1
replace variable = "inctot"     if variable == "`i'"
local i = `i' + 1
replace variable = "timemarr"   if variable == "`i'"
local i = `i' + 1
replace variable = "nchild_l5"  if variable == "`i'"
local i = `i' + 1
replace variable = "nchild"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhsize"     if variable == "`i'"
local i = `i' + 1
replace variable = "hhinc"      if variable == "`i'"

replace level = "respondent"
replace level = "household" if variable == "hhsize" | variable == "nchild"   ///
							 | variable == "hhinc"  | variable == "timemarr" ///
							 | variable == "nchild_l5"
 
replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1

save "$TABLES\TABLEC3", replace

** GENERATE TABLE C3

use "$TABLES\TABLEC3", replace
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec3.tex", text replace
noisily display "\begin{table}[!h]"
noisily display "\centering"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics, Husbands \\ Replication of Table \ref{table1}}"
noisily display "\begin{tabular}{lccccrr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "                          & Mean & S.d. & Min. & Max. & Obs. & SB1-SB0 \\"
noisily display " \midrule"
noisily display "                          & \multicolumn{6}{c}{A. Individual characteristics} \\"
noisily display " \cmidrule(lr){2-7}\\"
local i = 1
noisily display "Age    &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Years since immigration &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Age at immigration &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Educational Attainment \\"
noisily display "\;\; Current student &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Years of schooling &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; No schooling &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Elementary &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; High school &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; College &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Race and ethnicity \\"
noisily display "\;\; Asian &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Black &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; White &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Other &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Hispanic &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Ability to speak English \\"
noisily display "\;\; Not at all &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Not well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Very well &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\\\"
local i = `i' + 1
noisily display "Labor market outcomes \\"
noisily display "\;\; Labor participant &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Employed &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (excl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Yearly weeks worked (incl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (excl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Weekly hours worked (incl. 0) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "\;\; Labor income (thds.) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display " \cmidrule(lr){2-7}"
noisily display "                          & \multicolumn{6}{c}{B. Household characteristics} \\"
noisily display " \cmidrule(lr){2-7} \\"
local i = `i' + 2
noisily display "Years since married &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children aged $ < $ 5 &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Number of children &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household size &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Household income (thds.) &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.1fc min[`i'] "&" %9.1fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec3} notes: The summary statistics are computed using husbands sample weights (\texttt{PERWT\_SP}) provided in the ACS \cite{ruggles2015}, except those for household characteristics, which are computed using household weights (\texttt{HHWT}). The last column reports the estimate $\widehat\beta$ from regressions of the type $ X_i=\alpha+\beta\;\texttt{SBI}+\varepsilon $, where $ X_i $ is an individual level characteristic, where \texttt{SBI} is the wife's. Robust standard errors are not reported. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec3}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C4: SUMMARY STATISTICS, HOUSEHOLDS
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

* SUMMARY STATISTICS, HOUSEHOLD GAPS

local variables "age_gap sp_citizen race_wt bpl_same language_same educ_sp_sup"
local variables "`variables' lfp_gap emp_gap eng_sp_sup wks_gap hrs_gap"
local variables "`variables' wks40_gap hrs30_gap incwage_gap nlabinc_gap "

foreach v of local variables {

	/* summary statistics */

	summarize `v' [aw=hhwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
	
	/* SB1 - SB0 */
	
	regress `v' sbi [pw=hhwt], robust
	parmest, saving(`v', replace)
}

** DATASET OF SUMMARY STATISTICS AND ESTIMATES

matrix TABLEC4 = J(15,10,.)

local j = 0
foreach v of local variables {
	local j = `j' + 1
	
	use `v', clear
	
	matrix TABLEC4[`j',1] = `j'                        /* variable name        */
	matrix TABLEC4[`j',3] = mean_`v'                   /* mean                 */
	matrix TABLEC4[`j',4] = sd_`v'                     /* s.d.                 */
	matrix TABLEC4[`j',5] = min_`v'                    /* min                  */
	matrix TABLEC4[`j',6] = max_`v'                    /* max                  */
	matrix TABLEC4[`j',7] = n_`v'                      /* observations         */
	matrix TABLEC4[`j',8] = estimate[1]                /* estimates on SBI = 1 */
	matrix TABLEC4[`j',9] = p[1]                       /* p-value              */
	
	erase `v'.dta
}

drop _all
svmat TABLEC4

rename TABLEC41  variable
rename TABLEC42  level
rename TABLEC43  mean
rename TABLEC44  sd
rename TABLEC45  min
rename TABLEC46  max
rename TABLEC47  n
rename TABLEC48  estimate
rename TABLEC49  p
rename TABLEC410 stars

foreach v of varlist variable-level stars {
	tostring `v', replace
}

local i = 1
replace variable = "age_gap"       if variable == "`i'"
local i = `i' + 1
replace variable = "sp_citizen"    if variable == "`i'"
local i = `i' + 1
replace variable = "race_wt"       if variable == "`i'"
local i = `i' + 1
replace variable = "bpl_same"      if variable == "`i'"
local i = `i' + 1
replace variable = "language_same" if variable == "`i'"
local i = `i' + 1
replace variable = "educ_sp_sup"   if variable == "`i'"
local i = `i' + 1
replace variable = "lfp_gap"       if variable == "`i'"
local i = `i' + 1
replace variable = "emp_gap"       if variable == "`i'"
local i = `i' + 1
replace variable = "eng_sp_sup"    if variable == "`i'"
local i = `i' + 1
replace variable = "wks_gap"       if variable == "`i'"
local i = `i' + 1
replace variable = "hrs_gap"       if variable == "`i'"
local i = `i' + 1
replace variable = "wks40_gap"     if variable == "`i'"
local i = `i' + 1
replace variable = "hrs30_gap"     if variable == "`i'"
local i = `i' + 1
replace variable = "incwage_gap"   if variable == "`i'"
local i = `i' + 1
replace variable = "nlabinc_gap"   if variable == "`i'"

replace level = "household"

replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1

save "$TABLES\TABLEC4", replace

** GENERATE TABLE C4

use "$TABLES\TABLEC4", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec4.tex", text replace
noisily display "\begin{table}[p]"
noisily display "\centering"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics\\ Households with Female Immigrants, Married, Spouse Present, Aged 25-49\\ H: husband; W: wife}"
noisily display "\begin{tabular}{llccccrr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "                & Definition      & Mean & S.d. & Min. & Max. & Obs. & SB1-SB0 \\"
noisily display " \midrule"
local i = 1
noisily display "Age gap  & H age - W age    &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "American husband  & H $ = $ U.S. citizen   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "White husband  & H $ = $ white and W $ \neq $ white   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Origin homophily  & H COB $ = $ W COB   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Linguistic homophily  & H language $ = $ W language   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Education gap & H education $ > $ W education   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Labor participation gap & H LFP - W LFP   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Employment gap & H employment - W employment   &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.2fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 2
noisily display "Weeks gap & H weeks worked - W weeks worked   &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Hours gap & H hours worked - W hours worked  &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 3
noisily display "Labor income gap (thds.) & H labor income - W labor income   &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
local i = `i' + 1
noisily display "Non labor participation gap (thds.) & H non labor income - W non labor income &" %9.1fc mean[`i'] "&" %9.1fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "&" %9.1fc estimate[`i'] "" stars[`i'] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec4} notes: The summary statistics are computed using sample weights (\texttt{perwt}) provided in the ACS \cite{ruggles2015}. The last column reports the estimate $\widehat\beta$ from regressions of the type $ X_i=\alpha+\beta\;\texttt{SBI}+\varepsilon $, where $ X_i $ is an individual level characteristic. Robust standard errors are not reported. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec4}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C5: SUMMARY STATISTICS, COUNTRY AND COUNTY-LEVEL VARIABLES
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

local variables "ratio_lfp_i_n lfp_cob tfr nchild_cob yr_sch_ratio educyrs_cob"
local variables "`variables' mig gdpko_n comlang_ethno gendist_weight distcap"
local variables "`variables' lat lon sh_bpl_w sh_lang_w"

foreach v of local variables {

	summarize `v' [aw=perwt]
	scalar mean_`v' = r(mean)
	scalar sd_`v'   = r(sd)
	scalar n_`v'    = r(N)
	scalar min_`v'  = r(min)
	scalar max_`v'  = r(max)
}

** DATASET OF SUMMARY STATISTICS

matrix TABLEC5 = J(15,6,.)

local j = 0
foreach v of local variables {
	local j = `j' + 1
		
	matrix TABLEC5[`j',1] = `j'                        /* variable name        */
	matrix TABLEC5[`j',2] = mean_`v'                   /* mean                 */
	matrix TABLEC5[`j',3] = sd_`v'                     /* s.d.                 */
	matrix TABLEC5[`j',4] = min_`v'                    /* min                  */
	matrix TABLEC5[`j',5] = max_`v'                    /* max                  */
	matrix TABLEC5[`j',6] = n_`v'                      /* observations         */
}

drop _all
svmat TABLEC5

rename TABLEC51  variable
rename TABLEC52  mean
rename TABLEC53  sd
rename TABLEC54  min
rename TABLEC55  max
rename TABLEC56  n

tostring variable, replace

local i = 1
replace variable = "ratio_lfp_i_n"  if variable == "`i'"
local i = `i' + 1
replace variable = "lfp_cob"        if variable == "`i'"
local i = `i' + 1
replace variable = "tfr"            if variable == "`i'"
local i = `i' + 1
replace variable = "nchild_cob"     if variable == "`i'"
local i = `i' + 1
replace variable = "yr_sch_ratio"   if variable == "`i'"
local i = `i' + 1
replace variable = "educyrs_cob"    if variable == "`i'"
local i = `i' + 1
replace variable = "mig"            if variable == "`i'"
local i = `i' + 1
replace variable = "gdpko_n"        if variable == "`i'"
local i = `i' + 1
replace variable = "comlang_ethno"  if variable == "`i'"
local i = `i' + 1
replace variable = "gendist_weight" if variable == "`i'"
local i = `i' + 1
replace variable = "distcap"        if variable == "`i'"
local i = `i' + 1
replace variable = "lat"            if variable == "`i'"
local i = `i' + 1
replace variable = "lon"            if variable == "`i'"
local i = `i' + 1
replace variable = "sh_bpl_w"       if variable == "`i'"
local i = `i' + 1
replace variable = "sh_lang_w"      if variable == "`i'"

save "$TABLES\TABLEC5", replace

** GENERATE TABLE C5

use "$TABLES\TABLEC5", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec5.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Summary Statistics, Country and County Level Variables\\ Female Immigrants, Married, Spouse Present, Aged 25-49}"
noisily display "\begin{tabular}{llccccr}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " Variable        & Unit   & Mean & S.d. & Min. & Max. & Obs. \\"
noisily display " \midrule"
local i = 1
noisily display "COB LFP & Ratio female to male, \% &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "Ancestry LFP & \% & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB fertility & Number of children & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "Ancestry fertility & Number of children & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB education  & Ratio female to male, \% &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "Ancestry educaiton & Years of schooling &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB migration rate & \% & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB GDP per capita & PPP 2011 US \$ & " %9.0fc mean[`i'] "&" %9.0fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB and U.S. common language & Indicator & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "Genetic distance COB to U.S. & & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.2fc min[`i'] "&" %9.2fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "Bilateral distance COB to U.S. & Km & " %9.0fc mean[`i'] "&" %9.0fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB latitude & Degrees & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "COB longitude & Degrees & " %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "County COB density & \% &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
local i = `i' + 1
noisily display "County language density & \% &" %9.2fc mean[`i'] "&" %9.2fc sd[`i'] "&" %9.0fc min[`i'] "&" %9.0fc max[`i'] "&" %9.0fc n[`i'] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec5} notes: The summary statistics are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{appendix_cob_variables} for more details on variables sources and definitions.}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec5}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C6: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "hhsize i.state"
local controls_std    "age_std age_sq_std i.year i.race hispan ageimmig_std"
local controls_std    "`controls_std' age_3034 age_3539 age_4044 age_4549"
local controls_std    "`controls_std' yrsusa_std student englvl_std"
local controls_std    "`controls_std' i.dcimmig"
local controlshh_std  "hhsize_std i.state"

** CREATE STANDARDIZED VALUES

local variables "lfp sbi age age_sq ageimmig yrsusa educyrs"
local variables "`variables' englvl nchild_l5 hhsize"

foreach v of local variables {
	egen `v'_std = std(`v')
}

local variables "lfp sbi"

foreach v of local variables {
	replace `v'_std = `v'                  /* indicators are not standardized */
}

** SUMMARY STATISTICS FOR LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)

** REGRESSIONS

*** REGULAR REGRESSIONS

**** SPECIFICATION 1: NO CONTROLS

regress lfp sbi [pw=perwt], robust
parmest, saving(lfp_sbi_1, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 2: EDUCATION CONTROL

regress lfp sbi educyrs [pw=perwt], robust
parmest, saving(lfp_sbi_2, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 3: FERTILITY CONTROL

regress lfp sbi nchild_l5 [pw=perwt], robust
parmest, saving(lfp_sbi_3, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 4: EDUCATION AND FERTILITY CONTROLS

regress lfp sbi educyrs nchild_l5 [pw=perwt], robust
parmest, saving(lfp_sbi_4, replace) stars(0.1 0.05 0.01) es(N r2)

**** SPECIFICATION 5: INDIVIDUAL AND HOUSEHOLD CONTROLS

regress lfp sbi educyrs nchild_l5  `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_5, replace) stars(0.1 0.05 0.01) es(N r2)

*** STANDARDIZED REGRESSIONS

regress lfp_std sbi_std [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_1, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std educyrs_std [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_2, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std nchild_l5_std [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_3, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std educyrs_std nchild_l5_std [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_4, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp_std sbi_std educyrs_std nchild_l5_std  `controls_std'            ///
		`controlshh_std' [pw=perwt], robust
parmest, saving(lfp_std_sbi_std_5, replace) stars(0.1 0.05 0.01) es(N r2)	

*** RESIDUAL VARIANCE IN SB

sum sbi
scalar sbi_resvar_1 = r(Var)

regress sbi educyrs  [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_2 = r(Var)
drop sbi_res

regress sbi nchild_l5 [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_3 = r(Var)
drop sbi_res

regress sbi educyrs nchild_l5 [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_4 = r(Var)
drop sbi_res

regress sbi educyrs nchild_l5 `controls' `controlshh' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_5 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 5 {

	use lfp_sbi_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi" | variable == "educyrs" |                      ///
			variable == "nchild_l5"
	
	save lfp_sbi_`i'_modif, replace
	erase lfp_sbi_`i'.dta
}

forvalues i = 1 / 5 {

	use lfp_std_sbi_std_`i', clear
	
	generate outcome  = "lfp_std"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_std" | variable == "educyrs_std" |              ///
			variable == "nchild_l5_std"
	
	save lfp_std_sbi_std_`i'_modif, replace
	erase lfp_std_sbi_std_`i'.dta
}

** APPEND

clear
forvalues i = 1 / 5 {
	append using lfp_sbi_`i'_modif
	append using lfp_std_sbi_std_`i'_modif
	erase lfp_sbi_`i'_modif.dta
	erase lfp_std_sbi_std_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .
replace  mean = mean_lfp if outcome == "lfp"

	
forvalues i = 1 / 5 {
	cap replace resid_variance = sbi_resvar_`i' if specification == "`i'"
}

save "$TABLES\TABLEC6", replace

** GENERATE TABLE C6

use "$TABLES\TABLEC6", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec6.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Individual Level\\ Replication of Columns 1 and 2 of Table \ref{table3}}"
noisily display "\begin{tabular}{lccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:  & \multicolumn{5}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-6}"
noisily display " & (1) & (2) & (3) & (4) & (5) \\"
noisily display "\cmidrule(lr){2-6} "
noisily display "Sex-based       &" %9.3fc b[1] "" stars[1] "&" %9.3fc b[3] "" stars[3] "&" %9.3fc b[7] "" stars[7] "&" %9.3fc b[11] "" stars[11] "  &" %9.3fc b[17] "" stars[17] "\\"
noisily display "                & [\rm" %9.3fc se[1] "]     & [\rm" %9.3fc se[3] "]     & [\rm" %9.3fc se[7] "]     & [\rm" %9.3fc se[11] "]       & [\rm" %9.3fc se[17] "]       \\"
noisily display "$ \beta $-coef. &    " %9.3fc b[2] "        & " %9.3fc b[5] "           & " %9.3fc b[9] "           & " %9.3fc b[14] "            & " %9.3fc b[20] "                                    \\\\" 
noisily display "Years of schooling &                        &" %9.3fc b[4] "" stars[4] "&                           &" %9.3fc b[12] "" stars[12] "  &" %9.3fc b[18] "" stars[18] "\\"
noisily display "                &                           & [\rm" %9.3fc se[4] "]     &                           & [\rm" %9.3fc se[12] "]       &  [\rm" %9.3fc se[18] "]                             \\"
noisily display "$ \beta $-coef. &                           & " %9.3fc b[6] "           &                           & " %9.3fc b[15] "            & " %9.3fc b[21] "                                        \\\\" 
noisily display "Number of children $<$ 5    &               &                           &" %9.3fc b[8] "" stars[8] " &" %9.3fc b[13] "" stars[13] "  &" %9.3fc b[19] "" stars[19] "\\"
noisily display "                &                           &                           &  [\rm" %9.3fc se[8] "]     & [\rm" %9.3fc se[13] "]       &  [\rm" %9.3fc se[19] "]                              \\"
noisily display "$ \beta $-coef. &                           &                           & " %9.3fc b[10] "            & " %9.3fc b[16] "            & " %9.3fc b[22] "                                         \\\\" 
noisily display "Respondent char. & No & No & No & No & Yes \\"
noisily display "Household char. & No & No & No & No & Yes \\\\"
noisily display "Observations &" %9.0fc n[1] "&" %9.0fc n[4] "&" %9.0fc n[8] "&" %9.0fc n[11] "&" %9.0fc n[17] "\\"
noisily display "R$^2$ &" %9.3fc r2[1] "&" %9.3fc r2[4] "&" %9.3fc r2[8] "&" %9.3fc r2[11] "&" %9.3fc r2[17] "\\\\"
noisily display "Mean &" %9.2fc mean[1] "&" %9.2fc mean[4] "&" %9.2fc mean[8] "&" %9.2fc mean[11] "&" %9.2fc mean[17] "\\"
noisily display "\texttt{SB} residual variance &" %9.3fc resid_variance[1] "&" %9.3fc resid_variance[4] "&" %9.3fc resid_variance[8] "&" %9.3fc resid_variance[11] "&" %9.3fc resid_variance[17] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec6} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec6}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C7: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, ADL OUTCOMES
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** GENERATE TOP_INTENSITY

generate gii_4 = .
replace gii_4 = 0 if gii_3 == 0 | gii_3 == 1 | gii_3 == 2
replace gii_4 = 1 if gii_3 == 3

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"
local outcomes    "lfp emp wks0 wks hrs0 hrs"
local language    "gii_1 gii_2 gii_3 gii_pca gii_4"

** SUMMARY STATISTICS

foreach o of local outcomes {
	summarize   `o' [aw=perwt]
	scalar mean_`o' = r(mean)
}

** REGRESSIONS

foreach l of local language {
	foreach o of local outcomes {
		regress `o' `l' `controls' `controlshh' i.bpl [pw=perwt], robust
		parmest, saving(`o'_`l'_5, replace) stars(0.1 0.05 0.01) es(N r2)	
	}
}

** CREATE DATASET OF SUMMARY STATISTICS AND ESTIMATES

foreach l of local language {
	foreach o of local outcomes {
		
			use `o'_`l'_5, clear
			
			generate outcome  = "`o'"
			generate specification = "5"
			rename es_1 n
			rename es_2 r2
			rename parm variable
			rename stderr se
			rename estimate b
			
			order outcome specification variable, first
			
			keep if variable == "`l'"
			
			save `o'_`l'_5_modif, replace
			erase `o'_`l'_5.dta
	}
}

** APPEND

foreach l of local language {
	clear
	foreach o of local outcomes {
			append using `o'_`l'_5_modif
			erase `o'_`l'_5_modif.dta
	}
	save tablec7_`l'_rep, replace
}

*** ADD SUMMARY STATISTICS

foreach l of local language {
	use tablec7_`l'_rep, clear
	
	generate mean = .

	foreach o of local outcomes {

		replace  mean = mean_`o' if outcome == "`o'"
	}
	
	save estimates_tablec7_`l'_rep, replace
	erase tablec7_`l'_rep.dta
}

clear
foreach l of local language {
	append using estimates_tablec7_`l'_rep
	erase estimates_tablec7_`l'_rep.dta
}

generate order = 0
replace order = 1 if outcome == "emp"
replace order = 2 if outcome == "wks0"
replace order = 4 if outcome == "wks"
replace order = 3 if outcome == "hrs0"
replace order = 5 if outcome == "hrs"

generate order_lang = 1
replace  order_lang = 2 if variable == "gii_1"
replace  order_lang = 3 if variable == "gii_2"
replace  order_lang = 4 if variable == "gii_3"
replace  order_lang = 5 if variable == "gii_pca"
replace  order_lang = 6 if variable == "gii_4"
sort order_lang order

save "$TABLES\TABLEC7", replace

** GENERATE TABLE C7

use "$TABLES\TABLEC7", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec7.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Additional Outcomes \\ Replication of Column 5 of Table \ref{table3}, Language Indices}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & \multicolumn{2}{c}{Extensive margin} & \multicolumn{4}{c}{Intensive margins} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){2-3}  \cmidrule(l{2pt}r{2pt}){4-7} "
noisily display " & \multicolumn{2}{c}{} & \multicolumn{2}{c}{Including zeros} & \multicolumn{2}{c}{Excluding zeros} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){4-5} \cmidrule(l{2pt}r{2pt}){6-7} "
noisily display "Dependent variable:  & LFP & Employed & Weeks & Hours & Weeks & Hours \\"
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel A. \texttt{Intensity\_1} $=$ \texttt{(SB $+$ GP $+$ GA $+$ NG) $ \times $ SB}} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 1
noisily display "\texttt{Intensity\_1} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel B. \texttt{Intensity\_2} $=$ \texttt{(SB $+$ GP $+$ NG) $ \times $ SB}} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 7
noisily display "\texttt{Intensity\_2} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel C. \texttt{Intensity} $=$ \texttt{(GP $+$ GA $+$ NG) $ \times $ SB}} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 13
noisily display "\texttt{Intensity} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel D. \texttt{Intensity\_PCA}} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 19
noisily display "\texttt{Intensity\_{PCA}} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\"
noisily display "\cmidrule(lr){2-7} "
noisily display " & \multicolumn{6}{c}{Panel E. \texttt{Top\_{Intensity}} $=$ 1 if \texttt{Intensity} $=$ 3, $=$ 0 otherwise} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 25
noisily display "\texttt{Top\_{Intensity}} &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]          \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "\\\\"
noisily display "Respondent char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Household char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Respondent COB FE & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.1fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.1fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec7} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec7}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C8: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, ALT SAMPLES
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if female     == 1                                             /* female */

forvalues i = 1 / 7 {
	generate sample`i' = 0
}

*** SAMPLE 1: ORIGINAL SAMPLE

replace sample1 = 1 if ((age < 50 & age >= 25) & sp_present == 1             ///
						& hhtype == 1 & female_sp != 1 & language_ipums != 1)
						
*** SAMPLE 2: 15-59
						
replace sample2 = 1 if ((age < 60 & age >= 15) & sp_present == 1             ///
						& hhtype == 1 & female_sp != 1 & language_ipums != 1)
						
*** SAMPLE 3: INDIGENOUS LANGUAGES
						
replace sample3 = 1 if (sample1 == 1 & language_share != 0)

*** SAMPLE 4: EXCLUDE ENGLISH SPEAKERS

replace sample4 = 1 if ((age < 50 & age >= 25) & sp_present == 1             ///
						& hhtype == 1 & female_sp != 1)
						
*** SAMPLE 5: EXCLUDE MEXICANS
						
replace sample5 = 1 if (sample1 == 1 & bpl != 20000)

*** SAMPLE 6: ALL HOUSEHOLDS

replace sample6 = 1 if (age < 50 & age >= 25 & language_ipums != 1)

*** SAMPLE 7: NO LANGUAGE QUALITY FLAGS

replace sample7 = 1 if (sample1 == 1 & qlanguag == 0)

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"
local outcomes    "lfp emp wks0 wks hrs0 hrs"

** SUMMARY STATISTICS

forvalues i = 1 / 7 {
	foreach o of local outcomes {

		summarize   `o' if sample`i' == 1 [aw=perwt]
		scalar mean_`o'_`i' = r(mean)
	}
}

** REGRESSIONS

forvalues i = 1 / 7 {
	foreach o of local outcomes {
		
		regress `o' sbi `controls' `controlshh' i.bpl  if sample`i' == 1     ///
				[pw=perwt], robust
		parmest, saving(`o'_sample`i', replace) stars(0.1 0.05 0.01) es(N r2)
		
	}
}

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 7 {
	foreach o of local outcomes {
		
		use `o'_sample`i', clear
		
		generate outcome  = "`o'"
		generate sample   = "`i'"
		rename es_1 n
		rename es_2 r2
		rename parm variable
		rename stderr se
		rename estimate b
		
		order outcome sample variable, first
		
		keep if variable == "sbi"
		
		save `o'_sample`i'_modif, replace
		erase `o'_sample`i'.dta
	}
}

*** APPEND

forvalues i = 1 / 7 {
	clear
	foreach o of local outcomes {
		append using `o'_sample`i'_modif
		erase `o'_sample`i'_modif.dta
	}
	save tablec8_sample`i', replace
}

*** ADD SUMMARY STATISTICS

forvalues i = 1 / 7 {
	use tablec8_sample`i', clear
	
	generate mean = .

	foreach o of local outcomes {

		replace  mean = mean_`o'_`i' if outcome == "`o'"
	}

	save estimates_tablec8_sample`i', replace
	erase tablec8_sample`i'.dta
}

clear
forvalues i = 1 / 7 {
	append using estimates_tablec8_sample`i'
	erase estimates_tablec8_sample`i'.dta
}

generate order = 1
replace order  = 2 if outcome == "emp"
replace order  = 3 if outcome == "wks0"
replace order  = 4 if outcome == "hrs0"
replace order  = 5 if outcome == "wks"
replace order  = 6 if outcome == "hrs"
sort order sample

save "$TABLES\TABLEC8", replace

** GENERATE TABLE C8

use "$TABLES\TABLEC8", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec8.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\scriptsize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Alternative Samples \\ Replication of Column 5 of Table \ref{table3}}"
noisily display "\begin{tabular}{lccccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel A. Labor force participation} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 1
noisily display "Sex-based &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.3fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "]\\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel B. Employed} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 8
noisily display "Sex-based &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.3fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "] \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel C. Weeks worked, including zeros} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 15
noisily display "Sex-based &" %9.2fc b[`i'] "" stars[`i'] "&" %9.2fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.2fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.2fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.2fc se[`i'] "]       & [\rm" %9.2fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.2fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.2fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "]\\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.1fc mean[`i'] "&" %9.1fc mean[`i'+1] "&" %9.1fc mean[`i'+2] "&" %9.1fc mean[`i'+3] "&" %9.1fc mean[`i'+4] "&" %9.1fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel D. Hours worked, including zeros} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 22
noisily display "Sex-based &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.3fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "]\\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel E. Weeks worked, excluding zeros} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 29
noisily display "Sex-based &" %9.2fc b[`i'] "" stars[`i'] "&" %9.2fc b[`i'+1] "" stars[`i'+1] "&" %9.2fc b[`i'+2] "" stars[`i'+2] "&" %9.2fc b[`i'+3] "" stars[`i'+3] "&" %9.2fc b[`i'+4] "" stars[`i'+4] "&" %9.2fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.2fc se[`i'] "]       & [\rm" %9.2fc se[`i'+1] "]        & [\rm" %9.2fc se[`i'+2] "]         & [\rm" %9.2fc se[`i'+3] "]         & [\rm" %9.2fc se[`i'+4] "]          & [\rm" %9.2fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "]\\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.1fc mean[`i'] "&" %9.1fc mean[`i'+1] "&" %9.1fc mean[`i'+2] "&" %9.1fc mean[`i'+3] "&" %9.1fc mean[`i'+4] "&" %9.1fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-8} "
noisily display " & \multicolumn{7}{c}{Panel F. Hours worked, excluding zeros} \\"
noisily display "\cmidrule(lr){2-8} "
local i = 36
noisily display "Sex-based &" %9.3fc b[`i'] "" stars[`i'] "&" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'] "]       & [\rm" %9.3fc se[`i'+1] "]        & [\rm" %9.3fc se[`i'+2] "]         & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "]          & [\rm" %9.3fc se[`i'+5] "]         & [\rm" %9.3fc se[`i'+6] "] \\\\"
noisily display "Observations &" %9.0fc n[`i'] "&" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'] "&" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'] "&" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\\\"
noisily display "Sample & Baseline & Age 15-59 & Indig. & Include & Exclude & All & Qual. \\"
noisily display " &  &  & lang. & English & Mexicans & hh & flags \\\\"
noisily display "Respondent char. & Yes & Yes & Yes & Yes & Yes  & Yes & Yes  \\"
noisily display "Household char. & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\"
noisily display "Respondent COB FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \scriptsize{Table \ref{tablec8} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \scriptsize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec8}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C9: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, LOGIT AND PROBIT
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"
local outcomes    "lfp emp"
local estimator   "logit probit"

** SUMMARY STATISTICS

foreach o of local outcomes {

	summarize   `o' [aw=perwt]
	scalar mean_`o' = r(mean)
}

** REGRESSIONS

*** REGRESSIONS (LOGIT AND PROBIT)

matrix TABLEC9 = J(12,12,.)

local j = 0
local m = 0
foreach e of local estimator {
	local m = `m' + 1
	local k = 0
	foreach o of local outcomes {
		local k = `k' + 1
		
		**** SPECIFICATION 1: NO CONTROLS

		`e' `o' sbi [pw=perwt], robust iterate(5)
		
		local r2 = e(r2_p)
		local df = e(df_m)
		
		margins, dydx(sbi) atmeans post
		
		local j = `j' + 1
		
		matrix TABLEC9[`j',1]  = `m'                         /* estimator     */
		matrix TABLEC9[`j',2]  = `k'                         /* outcome       */
		matrix TABLEC9[`j',3]  =  1                          /* specification */
		matrix TABLEC9[`j',4]  = _b[sbi]
		matrix TABLEC9[`j',5]  = _se[sbi]
		matrix TABLEC9[`j',6]  = _b[sbi] - 1.96 * _se[sbi]
		matrix TABLEC9[`j',7]  = _b[sbi] + 1.96 * _se[sbi]
		local t = _b[sbi] / _se[sbi]
		matrix TABLEC9[`j',8]  = 2*ttail(`df',abs(`t'))
		matrix TABLEC9[`j',10] = e(N)
		matrix TABLEC9[`j',11] = `r2'
		matrix TABLEC9[`j',12] = mean_`o'
		
		**** SPECIFICATION 5: INDIVIDUAL AND HOUSEHOLD CONTROLS
		
		`e' `o' sbi `controls' `controlshh' i.bpl [pw=perwt], robust iterate(5)
		
		local r2 = e(r2_p)
		local df = e(df_m)
		
		margins, dydx(sbi) atmeans post
		
		local j = `j' + 1
		
		matrix TABLEC9[`j',1]  = `m'                         /* estimator     */
		matrix TABLEC9[`j',2]  = `k'                         /* outcome       */
		matrix TABLEC9[`j',3]  =  5                          /* specification */
		matrix TABLEC9[`j',4]  = _b[sbi]
		matrix TABLEC9[`j',5]  = _se[sbi]
		matrix TABLEC9[`j',6]  = _b[sbi] - 1.96 * _se[sbi]
		matrix TABLEC9[`j',7]  = _b[sbi] + 1.96 * _se[sbi]
		local t = _b[sbi] / _se[sbi]
		matrix TABLEC9[`j',8]  = 2*ttail(`df',abs(`t'))
		matrix TABLEC9[`j',10] = e(N)
		matrix TABLEC9[`j',11] = `r2'
		matrix TABLEC9[`j',12] = mean_`o'
	}
}

drop _all
svmat TABLEC9

rename TABLEC91  estimator
rename TABLEC92  outcome
rename TABLEC93  specification
rename TABLEC94  b
rename TABLEC95  se
rename TABLEC96  min95
rename TABLEC97  max95
rename TABLEC98  p
rename TABLEC99  stars
rename TABLEC910 n
rename TABLEC911 r2
rename TABLEC912 mean

local var "estimator outcome stars"
foreach v of local var {
	tostring `v', replace
}

replace estimator = "logit"  if estimator == "1"
replace estimator = "probit" if estimator == "2"

replace outcome = "lfp"   if outcome == "1"
replace outcome = "emp"   if outcome == "2"

replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1	

save tablec9_temp, replace

*** REGRESSIONS (OLS)

**** LOAD THE DATA

use REH_final.dta, clear

**** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

**** SUMMARY STATISTICS

foreach o of local outcomes {

	summarize   `o' [aw=perwt]
	scalar mean_`o' = r(mean)
}

**** REGRESSIONS

matrix TABLEC9 = J(12,12,.)

local j = 0
local k = 0
foreach o of local outcomes {
	local k = `k' + 1
	
	**** SPECIFICATION 1: NO CONTROLS

	regress `o' sbi [pw=perwt], robust
	
	local df = e(df_m)
		
	local j = `j' + 1
	
	matrix TABLEC9[`j',1]  =  3                              /* estimator     */
	matrix TABLEC9[`j',2]  = `k'                             /* outcome       */
	matrix TABLEC9[`j',3]  =  1                              /* specification */
	matrix TABLEC9[`j',4]  = _b[sbi]
	matrix TABLEC9[`j',5]  = _se[sbi]
	matrix TABLEC9[`j',6]  = _b[sbi] - 1.96 * _se[sbi]
	matrix TABLEC9[`j',7]  = _b[sbi] + 1.96 * _se[sbi]
	local t = _b[sbi] / _se[sbi]
	matrix TABLEC9[`j',8]  = 2*ttail(`df',abs(`t'))
	matrix TABLEC9[`j',10] = e(N)
	matrix TABLEC9[`j',11] = e(r2)
	matrix TABLEC9[`j',12] = mean_`o'
	
	**** SPECIFICATION 5: INDIVIDUAL AND HOUSEHOLD CONTROLS
	
	regress `o' sbi `controls' `controlshh' i.bpl [pw=perwt], robust
	
	local df = e(df_m)
		
	local j = `j' + 1
	
	matrix TABLEC9[`j',1]  =  3                              /* estimator     */
	matrix TABLEC9[`j',2]  = `k'                             /* outcome       */
	matrix TABLEC9[`j',3]  =  5                              /* specification */
	matrix TABLEC9[`j',4]  = _b[sbi]
	matrix TABLEC9[`j',5]  = _se[sbi]
	matrix TABLEC9[`j',6]  = _b[sbi] - 1.96 * _se[sbi]
	matrix TABLEC9[`j',7]  = _b[sbi] + 1.96 * _se[sbi]
	local t = _b[sbi] / _se[sbi]
	matrix TABLEC9[`j',8]  = 2*ttail(`df',abs(`t'))
	matrix TABLEC9[`j',10] = e(N)
	matrix TABLEC9[`j',11] = e(r2)
	matrix TABLEC9[`j',12] = mean_`o'			
	
}

drop _all
svmat TABLEC9

rename TABLEC91  estimator
rename TABLEC92  outcome
rename TABLEC93  specification
rename TABLEC94  b
rename TABLEC95  se
rename TABLEC96  min95
rename TABLEC97  max95
rename TABLEC98  p
rename TABLEC99  stars
rename TABLEC910 n
rename TABLEC911 r2
rename TABLEC912 mean

local var "estimator outcome stars"
foreach v of local var {
	tostring `v', replace
}

replace estimator = "OLS"  if estimator == "3"

replace outcome = "lfp"   if outcome == "1"
replace outcome = "emp"   if outcome == "2"

replace stars = "***" if p <= .01
replace stars = "**"  if (p <= .05 & p > .01)
replace stars = "*"   if (p <= .1 & p > .05)
replace stars = ""    if p > .1	

append using tablec9_temp

generate varsort = 1
replace  varsort = 2 if estimator == "logit"
replace  varsort = 3 if estimator == "probit"

generate varsort1 = 1
replace  varsort1 = 2 if outcome == "emp"

sort varsort1 varsort specification
drop varsort varsort1
drop if b == .

save "$TABLES\TABLEC9", replace
erase tablec9_temp.dta

** GENERATE TABLE C9

use "$TABLES\TABLEC9", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec9.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Logit and Probit \\ Replication of Columns 1 and 5 of Table \ref{table3}}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & \multicolumn{2}{c}{OLS} & \multicolumn{2}{c}{Logit} & \multicolumn{2}{c}{Probit} \\"
noisily display "\cmidrule(l{2pt}r{2pt}){2-3} \cmidrule(l{2pt}r{2pt}){4-5} \cmidrule(l{2pt}r{2pt}){6-7} "
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7}"
noisily display " & \multicolumn{6}{c}{Panel A. Labor force participation} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 0
noisily display "Sex-based &" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'+1] "]       & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "] & [\rm" %9.3fc se[`i'+5] "] & [\rm" %9.3fc se[`i'+6] "]  \\\\"
noisily display "Observations &" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\"
noisily display "\cmidrule(lr){2-7}"
noisily display " & \multicolumn{6}{c}{Panel B. Employed} \\"
noisily display "\cmidrule(lr){2-7} "
local i = 6
noisily display "Sex-based &" %9.3fc b[`i'+1] "" stars[`i'+1] "&" %9.3fc b[`i'+2] "" stars[`i'+2] "&" %9.3fc b[`i'+3] "" stars[`i'+3] "&" %9.3fc b[`i'+4] "" stars[`i'+4] "&" %9.3fc b[`i'+5] "" stars[`i'+5] "&" %9.3fc b[`i'+6] "" stars[`i'+6] "\\"
noisily display "          & [\rm" %9.3fc se[`i'+1] "]       & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+3] "]         & [\rm" %9.3fc se[`i'+4] "] & [\rm" %9.3fc se[`i'+5] "] & [\rm" %9.3fc se[`i'+6] "]  \\\\"
noisily display "Observations &" %9.0fc n[`i'+1] "&" %9.0fc n[`i'+2] "&" %9.0fc n[`i'+3] "&" %9.0fc n[`i'+4] "&" %9.0fc n[`i'+5] "&" %9.0fc n[`i'+6] "\\"
noisily display "R$^2$ &" %9.3fc r2[`i'+1] "&" %9.3fc r2[`i'+2] "&" %9.3fc r2[`i'+3] "&" %9.3fc r2[`i'+4] "&" %9.3fc r2[`i'+5] "&" %9.3fc r2[`i'+6] "\\"
noisily display "Mean &" %9.2fc mean[`i'+1] "&" %9.2fc mean[`i'+2] "&" %9.2fc mean[`i'+3] "&" %9.2fc mean[`i'+4] "&" %9.2fc mean[`i'+5] "&" %9.2fc mean[`i'+6] "\\\\"
noisily display "Respondent char. & No & Yes & No & Yes & No & Yes \\"
noisily display "Household char. & No & Yes & No & Yes & No & Yes \\\\"
noisily display "Respondent COB FE & No & Yes & No & Yes & No & Yes \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec9} notes: This table replicates table \ref{table_indiv_sb} with additional outcomes and with different estimators. The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec9}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C10: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION, INDIVIDUAL LEVEL
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
drop if language_ipums_sp == 1            /* English-speaking husbands        */
drop if ageimmig_sp == 0

** DROP AND RENAME VARIABLES

local variables "age age_sq race hispan ageimmig yrsusa student educyrs englvl"
local variables "`variables' lfp emp wks0 wks hrs0 hrs perwt sbi ngi gpi gii_3"
foreach v of local variables {
	drop `v'
	rename `v'_sp `v'
}

local ages "1825 2024 2529 3034 3539 4044 4549 5054 5559 6064"
foreach a of local ages {
	drop age_`a'
	rename age_sp_`a' age_`a'
} 

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig age_2024 age_5054 age_5559 age_6064"
local controlshh  "nchild_l5 hhsize i.state"

** SUMMARY STATISTICS FOR LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)
summarize   lfp if county != 0 [aw=perwt]
scalar mean_lfp_7 = r(mean)

** REGRESSIONS

regress lfp sbi [pw=perwt], robust
parmest, saving(lfp_sbi_1, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp sbi `controls' `controlshh' [pw=perwt], robust
parmest, saving(lfp_sbi_2, replace) stars(0.1 0.05 0.01) es(N r2)


regress lfp sbi `controls' `controlshh' i.bpl_sp [pw=perwt], robust
parmest, saving(lfp_sbi_3, replace) stars(0.1 0.05 0.01) es(N r2)

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

forvalues i = 1 / 3 {

	use lfp_sbi_`i', clear
	
	generate outcome  = "lfp"
	generate specification = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi" 
	
	save lfp_sbi_`i'_modif, replace
	erase lfp_sbi_`i'.dta
}

*** APPEND

clear
forvalues i = 1 / 3 {
		append using lfp_sbi_`i'_modif
		erase lfp_sbi_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS

generate mean = .
generate resid_variance = .
replace  mean = mean_lfp if outcome == "lfp"

save "$TABLES\TABLEC10", replace

** GENERATE TABLE C10

use "$TABLES\TABLEC10", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec10.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation, Individual Level\\ Husbands of Female Immigrants, Married, Spouse Present, 25-49 (2005-2015)}"
noisily display "\begin{tabular}{lccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable:  & \multicolumn{3}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-4}"
noisily display " & (1) & (2) & (3)  \\"
noisily display "\cmidrule(lr){2-4} "
noisily display "Sex-based       &" %9.3fc b[1] "" stars[1] "&" %9.3fc b[2] "" stars[2] "& " %9.3fc b[3] "" stars[3]  "\\"
noisily display "                & [\rm" %9.3fc se[1] "]     & [\rm" %9.3fc se[2] "]     &  [\rm" %9.3fc se[3] "]      \\\\"
noisily display "Husband char. & No & Yes & Yes \\"
noisily display "Household char. & No & Yes & Yes \\\\"
noisily display "Husband COB FE & No & No & Yes \\\\"
noisily display "Observations &" %9.0fc n[1] "&" %9.0fc n[2] "&" %9.0fc n[3] "\\"
noisily display "R$^2$ &" %9.3fc r2[1] "&" %9.3fc r2[2] "&" %9.3fc r2[3] "\\\\"
noisily display "Mean &" %9.2fc mean[1] "&" %9.2fc mean[2] "&" %9.2fc mean[3] "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec10} notes: The estimates are computed using sample weights (\texttt{PERWT\_{SB}}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions. The husband characteristics are analogous to the respondent characteristics in Table \ref{table_indiv_sb}. The sample is the same as in Table \ref{table_indiv_sp} except that we drop English-speaking and native husbands.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec10}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C11: GENDER IN LANGUAGE AND ECONOMIC PARTICIPATION
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if female     == 1                                             /* female */
keep if (age < 50 & age >= 25 & language_ipums != 1)                /* all hh */

generate unmar = 0
replace unmar = 1 if marst != 1

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"

** SUMMARY STATISTICS FOR LFP

summarize   lfp [aw=perwt]
scalar mean_lfp = r(mean)

** REGRESSIONS

regress lfp sbi `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_1, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp unmar `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_2, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp sbi unmar `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_3, replace) stars(0.1 0.05 0.01) es(N r2)

regress lfp sbi##unmar `controls' `controlshh' i.bpl [pw=perwt], robust
parmest, saving(lfp_4, replace) stars(0.1 0.05 0.01) es(N r2)

** CREATE DATASET OF SUMMARY STATISTICS AND ESTIMATES

*** KEEP ESTIMATES FOR TABLE 

forvalues i = 1 / 4 {
	
	use lfp_`i', clear
	
	generate outcome  = "lfp"
	generate specification   = "`i'"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi" | variable == "unmar" | variable == "1.sbi" |  ///
			variable == "1.unmar" | variable == "1.sbi#1.unmar"
	
	save lfp_`i'_modif, replace
	erase lfp_`i'.dta
}

*** APPEND

clear
forvalues i = 1 / 4 {
	append using lfp_`i'_modif
	erase lfp_`i'_modif.dta
}

*** ADD SUMMARY STATISTICS

generate mean = .
replace  mean = mean_lfp

save "$TABLES\TABLEC11", replace

** GENERATE TABLE C11

use "$TABLES\TABLEC11", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec11.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Gender in Language and Economic Participation \\ Replication of Column 5 of Table \ref{table3}}"
noisily display "\begin{tabular}{lcccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display "Dependent variable & \multicolumn{4}{c}{Labor force participation} \\"
noisily display "\cmidrule(lr){2-5} "
noisily display " & (1) & (2) & (3) & (4)  \\"
noisily display "\cmidrule(lr){2-5} "
noisily display "Sex-based &" %9.3fc b[1] "" stars[1] "&&" %9.3fc b[3] "" stars[3] "&" %9.3fc b[5] "" stars[5] "\\"
noisily display "          & [\rm" %9.3fc se[1] "]       &      & [\rm" %9.3fc se[3] "] & [\rm" %9.3fc se[5] "]  \\\\"
noisily display "Unmarried &&" %9.3fc b[2] "" stars[2] "&" %9.3fc b[4] "" stars[4] "&" %9.3fc b[6] "" stars[6] "\\"
noisily display "          & & [\rm" %9.3fc se[2] "]             & [\rm" %9.3fc se[4] "] & [\rm" %9.3fc se[6] "]  \\\\"
noisily display "Sex-based $ \times $ unmarried &&& &" %9.3fc b[7] "" stars[7] "\\"
noisily display "          &     &      & & [\rm" %9.3fc se[7] "]   \\\\"
noisily display "Respondent char. & Yes & Yes & Yes & Yes  \\"
noisily display "Household char. & Yes & Yes & Yes & Yes   \\\\"
noisily display "Respondent COB FE & Yes & Yes & Yes & Yes  \\\\"
noisily display "Observations &" %9.0fc n[1] "&" %9.0fc n[2] "&" %9.0fc n[3] "&" %9.0fc n[5] "\\"
noisily display "R$^2$ &" %9.3fc r2[1] "&" %9.3fc r2[2] "&" %9.3fc r2[3]  "&" %9.3fc r2[5]  "\\"
noisily display "Mean &" %9.2fc mean[1] "&" %9.2fc mean[2] "&" %9.2fc mean[3]  "&" %9.2fc mean[5]  "\\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec11} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec11}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C12: LANGUAGE AND HOUSEHOLD BARGAINING
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
keep if language_wals == language_wals_sp /* same language                    */

** LOCALS

local controls        "age age_sq i.year i.race hispan ageimmig age_3034"
local controls        "`controls' age_3539 age_4044 age_4549 yrsusa student"
local controls        "`controls' educyrs englvl i.dcimmig"
local controlshh      "nchild_l5 hhsize i.state"
local bargain         "age_gap nlabinc_gap"
local husband         "age_sq_sp i.race_sp hispan_sp ageimmig_sp yrsusa_sp"
local husband         "`husband' wks0_sp student_sp englvl_sp educyrs_sp"
local outcomes       "lfp emp wks0 wks hrs0 hrs"
local controls_std   "age_std age_sq_std i.year i.race hispan ageimmig_std"
local controls_std   "`controls_std' age_3034 age_3539 age_4044 age_4549"
local controls_std   "`controls_std' yrsusa_std student educyrs_std englvl_std"
local controls_std   "`controls_std' i.dcimmig"
local controlshh_std "nchild_l5_std hhsize_std i.state"
local bargain_std    "age_gap_std nlabinc_gap_std"
local husband_std    "age_sq_sp_std i.race_sp hispan_sp ageimmig_sp_std"
local husband_std    "`husband_std' yrsusa_sp_std wks0_sp_std student_sp"
local husband_std    "`husband_std' englvl_sp_std educyrs_sp_std"
local outcomes_std   "lfp_std emp_std wks0_std wks_std hrs0_std hrs_std"

** CREATE STANDARDIZED VALUES

local variables "`outcomes' sbi age age_sq ageimmig yrsusa educyrs"
local variables "`variables' englvl nchild_l5 hhsize age_gap nlabinc_gap"
local variables "`variables' educyrs_sp age_sq_sp ageimmig_sp yrsusa_sp wks0_sp"
local variables "`variables' englvl_sp"
foreach v of local variables {
	egen `v'_std = std(`v')
}

local variables "lfp emp sbi"
foreach v of local variables {
	replace `v'_std = `v'                  /* indicators are not standardized */
}

** SUMMARY STATISTICS

foreach o of local outcomes {

	summarize   `o' [aw=perwt]
	scalar mean_`o' = r(mean)
}

** REGRESSIONS

*** REGULAR REGRESSIONS

foreach o of local outcomes {

	regress `o' c.age_gap##sbi c.nlabinc_gap##sbi                            ///
			`controls' `controlshh' `husband' i.bpl  [pw=perwt],             ///
			robust
	parmest, saving(`o'_sbi_6, replace) stars(0.1 0.05 0.01) es(N r2)		
	
}

*** STANDARDIZED REGRESSIONS

foreach o of local outcomes_std {

	regress `o' c.age_gap_std##sbi_std c.nlabinc_gap_std##sbi_std            ///
			 `controls_std' `controlshh_std'                                 ///
			`husband_std' i.bpl  [pw=perwt], robust
	parmest, saving(`o'_sbi_std_6, replace) stars(0.1 0.05 0.01) es(N r2)

}

*** RESIDUAL VARIANCE IN SB

regress sbi `bargain' `controls' `controlshh' `husband' i.bpl[pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_6 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

foreach o of local outcomes {
	
		use `o'_sbi_6, clear
		
		generate outcome  = "`o'"
		generate specification = "6"
		rename es_1 n
		rename es_2 r2
		rename parm variable
		rename stderr se
		rename estimate b
		
		order outcome specification variable, first
		
		keep if variable == "sbi" | variable == "age_gap" |                  ///
				variable == "nlabinc_gap" |                                  ///
				variable == "1.sbi" | variable == "1.sbi#c.age_gap" |        ///
				variable == "1.sbi#c.nlabinc_gap" 			
		save `o'_sbi_6_modif, replace
		erase `o'_sbi_6.dta
}

foreach o of local outcomes_std {
	
		cap use `o'_sbi_std_6, clear
		
		generate outcome  = "`o'"
		generate specification = "6"
		rename es_1 n
		rename es_2 r2
		rename parm variable
		rename stderr se
		rename estimate b
		
		order outcome specification variable, first
		
		keep if variable == "sbi_std" | variable == "age_gap_std" |          ///
				variable == "nlabinc_gap_std" |                              ///
				 variable == "1.sbi_std"  |                                  ///
				variable == "1.sbi_std#c.age_gap_std" |                      ///
				variable == "1.sbi_std#c.nlabinc_gap_std" 			
		save `o'_sbi_std_6_modif, replace
		erase `o'_sbi_std_6.dta
}

*** APPEND

clear
foreach o of local outcomes {
		append using `o'_sbi_6_modif
		cap append using `o'_std_sbi_std_6_modif
		erase `o'_sbi_6_modif.dta
		cap erase `o'_std_sbi_std_6_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .

foreach o of local outcomes {

	replace  mean = mean_`o' if outcome == "`o'"
}

cap replace resid_variance = sbi_resvar_6 if specification == "6"

save "$TABLES\TABLEC12", replace

** GENERATE TABLE C12

use "$TABLES\TABLEC12", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec12.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Language and Household Bargaining\\ Replication of Column 3 of Table \ref{table4}}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & \multicolumn{2}{c}{Extensive margin} & \multicolumn{4}{c}{Intensive margins} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){2-3}  \cmidrule(l{2pt}r{2pt}){4-7} "
noisily display " & \multicolumn{2}{c}{} & \multicolumn{2}{c}{Including zeros} & \multicolumn{2}{c}{Excluding zeros} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){4-5} \cmidrule(l{2pt}r{2pt}){6-7} "
noisily display "Dependent variable:  & LFP & Employed & Weeks & Hours & Weeks & Hours \\"
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7} "
local i = 0
noisily display "Sex-based                                    &" %9.3fc b[`i'+2] "" stars[`i'+2] "   &" %9.3fc b[`i'+12] "" stars[`i'+12] "   &" %9.3fc b[`i'+22] "" stars[`i'+22] "   &" %9.3fc b[`i'+32] "" stars[`i'+32] " &" %9.3fc b[`i'+42] "" stars[`i'+42] " &" %9.3fc b[`i'+52] "" stars[`i'+52] "\\"
noisily display "                                             & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+12] "]        & [\rm" %9.3fc se[`i'+22] "]        & [\rm" %9.3fc se[`i'+32] "]       & [\rm" %9.3fc se[`i'+42] "]       & [\rm" %9.3fc se[`i'+52] "]      \\"
noisily display "$ \beta $-coef.                              &" %9.3fc b[`i'+7] "               &" %9.3fc b[`i'+17] "              &" %9.3fc b[`i'+27] "              &" %9.3fc b[`i'+37] "              &" %9.3fc b[`i'+47] "              &" %9.3fc b[`i'+57] "  \\\\" 
local i = -1
noisily display "Age gap                                    &" %9.3fc b[`i'+2] "" stars[`i'+2] "   &" %9.3fc b[`i'+12] "" stars[`i'+12] "   &" %9.3fc b[`i'+22] "" stars[`i'+22] "   &" %9.3fc b[`i'+32] "" stars[`i'+32] " &" %9.3fc b[`i'+42] "" stars[`i'+42] " &" %9.3fc b[`i'+52] "" stars[`i'+52] "\\"
noisily display "                                             & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+12] "]        & [\rm" %9.3fc se[`i'+22] "]        & [\rm" %9.3fc se[`i'+32] "]       & [\rm" %9.3fc se[`i'+42] "]       & [\rm" %9.3fc se[`i'+52] "]      \\"
noisily display "$ \beta $-coef.                              &" %9.3fc b[`i'+7] "               &" %9.3fc b[`i'+17] "              &" %9.3fc b[`i'+27] "              &" %9.3fc b[`i'+37] "              &" %9.3fc b[`i'+47] "              &" %9.3fc b[`i'+57] "  \\\\" 
local i = 2
noisily display "Non-labor income gap                                    &" %9.3fc b[`i'+2] "" stars[`i'+2] "   &" %9.3fc b[`i'+12] "" stars[`i'+12] "   &" %9.3fc b[`i'+22] "" stars[`i'+22] "   &" %9.3fc b[`i'+32] "" stars[`i'+32] " &" %9.3fc b[`i'+42] "" stars[`i'+42] " &" %9.3fc b[`i'+52] "" stars[`i'+52] "\\"
noisily display "                                             & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+12] "]        & [\rm" %9.3fc se[`i'+22] "]        & [\rm" %9.3fc se[`i'+32] "]       & [\rm" %9.3fc se[`i'+42] "]       & [\rm" %9.3fc se[`i'+52] "]      \\"
noisily display "$ \beta $-coef.                              &" %9.3fc b[`i'+7] "               &" %9.3fc b[`i'+17] "              &" %9.3fc b[`i'+27] "              &" %9.3fc b[`i'+37] "              &" %9.3fc b[`i'+47] "              &" %9.3fc b[`i'+57] "  \\\\" 
local i = 1
noisily display "Age gap $ \times $ \texttt{SB}                                    &" %9.3fc b[`i'+2] "" stars[`i'+2] "   &" %9.3fc b[`i'+12] "" stars[`i'+12] "   &" %9.3fc b[`i'+22] "" stars[`i'+22] "   &" %9.3fc b[`i'+32] "" stars[`i'+32] " &" %9.3fc b[`i'+42] "" stars[`i'+42] " &" %9.3fc b[`i'+52] "" stars[`i'+52] "\\"
noisily display "                                             & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+12] "]        & [\rm" %9.3fc se[`i'+22] "]        & [\rm" %9.3fc se[`i'+32] "]       & [\rm" %9.3fc se[`i'+42] "]       & [\rm" %9.3fc se[`i'+52] "]      \\"
noisily display "$ \beta $-coef.                              &" %9.3fc b[`i'+7] "               &" %9.3fc b[`i'+17] "              &" %9.3fc b[`i'+27] "              &" %9.3fc b[`i'+37] "              &" %9.3fc b[`i'+47] "              &" %9.3fc b[`i'+57] "  \\\\" 
local i = 3
noisily display "Non-labor income gap  $ \times $ \texttt{SB}                                    &" %9.3fc b[`i'+2] "" stars[`i'+2] "   &" %9.3fc b[`i'+12] "" stars[`i'+12] "   &" %9.3fc b[`i'+22] "" stars[`i'+22] "   &" %9.3fc b[`i'+32] "" stars[`i'+32] " &" %9.3fc b[`i'+42] "" stars[`i'+42] " &" %9.3fc b[`i'+52] "" stars[`i'+52] "\\"
noisily display "                                             & [\rm" %9.3fc se[`i'+2] "]        & [\rm" %9.3fc se[`i'+12] "]        & [\rm" %9.3fc se[`i'+22] "]        & [\rm" %9.3fc se[`i'+32] "]       & [\rm" %9.3fc se[`i'+42] "]       & [\rm" %9.3fc se[`i'+52] "]      \\"
noisily display "$ \beta $-coef.                              &" %9.3fc b[`i'+7] "               &" %9.3fc b[`i'+17] "              &" %9.3fc b[`i'+27] "              &" %9.3fc b[`i'+37] "              &" %9.3fc b[`i'+47] "              &" %9.3fc b[`i'+57] "  \\\\" 
noisily display "Respondent char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Household char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Husband char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Respondent COB FE & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "Observations &" %9.0fc n[1] "&" %9.0fc n[11] "&" %9.0fc n[21] "&" %9.0fc n[31] "&" %9.0fc n[41] "&" %9.0fc n[51] "\\"
noisily display "R$^2$ &" %9.3fc r2[1] "&" %9.3fc r2[11] "&" %9.3fc r2[21] "&" %9.3fc r2[31] "&" %9.3fc r2[41] "&" %9.3fc r2[51] "\\\\"
noisily display "Mean &" %9.2fc mean[1] "&" %9.2fc mean[11] "&" %9.2fc mean[21] "&" %9.2fc mean[31] "&" %9.2fc mean[41] "&" %9.2fc mean[51] "\\"
noisily display "\texttt{SB} residual variance &" %9.3fc resid_variance[1] "& " %9.3fc resid_variance[11] "&" %9.3fc resid_variance[21] "&" %9.3fc resid_variance[31] "&" %9.3fc resid_variance[41] "&" %9.3fc resid_variance[51] " \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec12} notes: The estimates are computed using sample weights (\texttt{PERWT}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec12}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* TABLE C13: LINGUISTIC HETEROGENEITY IN THE HOUSEHOLD
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */
drop if bpl_sp == 0                       /* US-born husbands                 */
drop if citizen_sp == 0                   /* US citizens husbands             */
drop if (sbi_sp != 0 & sbi_sp != 1)       /* Husband's sbi present            */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig sp_eng"
local controlshh  "nchild_l5 hhsize i.state"
local husband     "age_sp age_sq_sp i.race_sp hispan_sp ageimmig_sp yrsusa_sp"
local husband     "`husband' nlabinc_sp wks0_sp educyrs_sp student_sp englvl_sp"
local controlscob "ratio_lfp_i_n lfp_cob nchild_cob tfr mig educyrs_cob"
local controlscob "`controlscob' yr_sch_ratio comlang_ethno distcap gdpko_n lat" 
local controlscob "`controlscob' lon gendist_weight i.cont"
local outcomes    "lfp emp wks0 hrs0 wks hrs"
local controlsfull "`controls' `controlshh' `husband'"

** SUMMARY STATISTICS

foreach o of local outcomes {

	summarize   `o' [aw=perwt]
	scalar mean_`o' = r(mean)
}

** REGRESSIONS

*** REGULAR REGRESSIONS

foreach o of local outcomes {

	regress `o' sbi_same sbi_dif sbi_sp_dif `controlsfull' [pw=perwt], robust 
	parmest, saving(`o'_3, replace) stars(0.1 0.05 0.01) es(N r2)	
}

*** RESIDUAL VARIANCE IN SB

regress sbi `controlsfull' [pw=perwt], robust
predict sbi_res, residuals
sum sbi_res
scalar sbi_resvar_3 = r(Var)
drop sbi_res

** CREATE DATASET OF SUMMARY STATISTICS, ESTIMATES, AND RESIDUAL VARIANCES

*** KEEP ESTIMATES FOR TABLE

foreach o of local outcomes {

	use `o'_3, clear
	
	generate outcome  = "`o'"
	generate specification = "3"
	rename es_1 n
	rename es_2 r2
	rename parm variable
	rename stderr se
	rename estimate b
	
	order outcome specification variable, first
	
	keep if variable == "sbi_same" | variable == "sbi_dif" |                 ///
			variable == "sbi_sp_dif"
	
	save `o'_3_modif, replace
	erase `o'_3.dta
}

*** APPEND

clear
foreach o of local outcomes {
	append using `o'_3_modif
	erase `o'_3_modif.dta
}

*** ADD SUMMARY STATISTICS AND RESIDUAL VARIANCE

generate mean = .
generate resid_variance = .

foreach o of local outcomes {
	replace  mean = mean_`o' if outcome == "`o'"
	cap replace resid_variance = sbi_resvar_3 if specification == "3"	
}

save "$TABLES\TABLEC13", replace

** GENERATE TABLE C13

use "$TABLES\TABLEC13", clear
set linesize 255

quietly {
capture log close
log using "$TABLES\tablec13.tex", text replace
noisily display "\begin{table}[htbp]"
noisily display "\centering"
noisily display "\captionsetup{justification=centering}"
noisily display "\footnotesize"
noisily display "\begin{threeparttable}"
noisily display "\caption{Linguistic Heterogeneity in the Household\\ Replication of Column 3 of Table \ref{table5}}"
noisily display "\begin{tabular}{lcccccc}"
noisily display "\toprule"
noisily display "\toprule"
noisily display " & \multicolumn{2}{c}{Extensive margin} & \multicolumn{4}{c}{Intensive margins} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){2-3}  \cmidrule(l{2pt}r{2pt}){4-7} "
noisily display " & \multicolumn{2}{c}{} & \multicolumn{2}{c}{Including zeros} & \multicolumn{2}{c}{Excluding zeros} \\"
noisily display " \cmidrule(l{2pt}r{2pt}){4-5} \cmidrule(l{2pt}r{2pt}){6-7} "
noisily display "Dependent variable:  & LFP & Employed & Weeks & Hours & Weeks & Hours \\"
noisily display " & (1) & (2) & (3) & (4) & (5) & (6) \\"
noisily display "\cmidrule(lr){2-7} "
noisily display "Same $ \times $ wife's sex-based         &" %9.3fc b[1] "" stars[1] "&" %9.3fc b[4] "" stars[4] "&" %9.3fc b[7] "" stars[7]   "&" %9.3fc b[10] "" stars[10] "&" %9.3fc b[13] "" stars[13] "&" %9.3fc b[16] "" stars[16] "\\"
noisily display "                                         & [\rm" %9.3fc se[1] "]     & [\rm" %9.3fc se[4] "]     & [\rm" %9.3fc se[7] "]       & [\rm" %9.3fc se[10] "]      & [\rm" %9.3fc se[13] "]      & [\rm" %9.3fc se[16] "]      \\\\"
noisily display "Different $ \times $ wife's sex-based    &" %9.3fc b[2] "" stars[2] "&" %9.3fc b[5] "" stars[5] "&" %9.3fc b[8] "" stars[8] "  &" %9.3fc b[11] "" stars[11] "&" %9.3fc b[14] "" stars[14] "&" %9.3fc b[17] "" stars[17] "\\"
noisily display "                                         &[\rm" %9.3fc se[2] "]      & [\rm" %9.3fc se[5] "]     & [\rm" %9.3fc se[8] "]       & [\rm" %9.3fc se[11] "]      & [\rm" %9.3fc se[14] "]      & [\rm" %9.3fc se[17] "]      \\\\" 
noisily display "Different $ \times $ husband's sex-based &" %9.3fc b[3] "" stars[3] "&" %9.3fc b[6] "" stars[6] "&" %9.3fc b[9] "" stars[9] "  &" %9.3fc b[12] "" stars[12] "&" %9.3fc b[15] "" stars[15] "&" %9.3fc b[18] "" stars[18] "\\"
noisily display "                                         &[\rm" %9.3fc se[3] "]      & [\rm" %9.3fc se[6] "]     & [\rm" %9.3fc se[9] "]       & [\rm" %9.3fc se[12] "]      & [\rm" %9.3fc se[15] "]      & [\rm" %9.3fc se[18] "]      \\\\" 
noisily display "Respondent char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Household char. & Yes & Yes & Yes & Yes & Yes & Yes \\"
noisily display "Husband char. & Yes & Yes & Yes & Yes & Yes & Yes \\\\"
noisily display "Observations &" %9.0fc n[1] "&" %9.0fc n[4] "&" %9.0fc n[7] "&" %9.0fc n[10] "&" %9.0fc n[13] "&" %9.0fc n[16] "\\"
noisily display "R$^2$ &" %9.3fc r2[1] "&" %9.3fc r2[4] "&" %9.3fc r2[7] "&" %9.3fc r2[10] "&" %9.3fc r2[13] "&" %9.3fc r2[16] "\\\\"
noisily display "Mean &" %9.2fc mean[1] "&" %9.2fc mean[4] "&" %9.2fc mean[7] "&" %9.2fc mean[10] "&" %9.2fc mean[13] "&" %9.2fc mean[16] "\\"
noisily display "\texttt{SB} residual variance &" %9.3fc resid_variance[1] "& " %9.3fc resid_variance[4] "&" %9.3fc resid_variance[7] "&" %9.3fc resid_variance[10] "&" %9.3fc resid_variance[13] "&" %9.3fc resid_variance[16] " \\"
noisily display "\bottomrule"
noisily display "\end{tabular}"
noisily display "\begin{tablenotes}[flushleft]"
noisily display "\setlength\labelsep{0pt}"
noisily display "\item \footnotesize{Table \ref{tablec13} notes: The estimates are computed using sample weights (\texttt{perwt}) provided in the ACS \cite{ruggles2015}. See appendix \ref{data_appendix} for details on variable sources and definitions.}"
noisily display "\item \footnotesize{$^{***}$ Significant at the 1 percent level. $^{**}$ Significant at the 5 percent level. $^{*}$ Significant at the 10 percent level}"
noisily display "\end{tablenotes}"
noisily display "\label{tablec13}"
noisily display "\end{threeparttable}"
noisily display "\end{table}"
log close
}
}

* FIGURE D1: REGRESSION WEIGHTS FOR TABLE 3 COLUMN 5
{
** LOAD THE DATA

use REH_final.dta, clear

** SELECT SAMPLE

keep if (age < 50 & age >= 25)            /* age group 25-49                  */
keep if female     == 1                   /* female                           */
keep if sp_present == 1                   /* married, spouse present          */
drop if female_sp  == 1                   /* drop same-sex couples            */
keep if hhtype     == 1                   /* married-couple family households */
drop if language_ipums == 1               /* English speakers at home         */

** LOCALS

local controls    "age age_sq i.year i.race hispan ageimmig age_3034 age_3539"
local controls    "`controls' age_4044 age_4549 yrsusa student educyrs englvl"
local controls    "`controls' i.dcimmig"
local controlshh  "nchild_l5 hhsize i.state"

** REGRESSION

regress sbi `controls' `controlshh' i.bpl [pw=perwt], robust

** GET RESIDUALS AND GENERATE REGRESSION WEIGHTS

predict sbi_resid, residuals
generate sbi_resid_sq = sbi_resid^2

preserve
collapse (sum) sbi_resid_sq
scalar total = sbi_resid_sq[1]
restore

generate weight = (100 * sbi_resid_sq) / total
collapse (sum) weight, by(bpl)
sort weight

save "$FIGURES\FIGURED1", replace

/* The map is then generated manually through ArcGIS */
}

timer off 2 /* 3,689 sec */
timer list
